Skip to content

Conversation

@s8n11c
Copy link
Contributor

@s8n11c s8n11c commented Sep 8, 2025

feat(provider/cloudimage): make baseURL optional and route absolute src via CDN

🔗 Linked issue

Resolves #1950 - Cloudimage: Absolute URLs bypass CDN and baseURL requirement creates friction with multi-origin backends

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • �� Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Problem:
In real-world applications, image sources often come as full URLs from multiple backend services (CMS, DAM, microservices). The current Cloudimage provider has two main issues:

  1. Absolute URLs bypass CDN: When src is an absolute URL, the provider returns it as-is, completely bypassing the Cloudimage CDN
  2. Required baseURL creates friction: The provider requires a single baseURL, but real apps often have images from multiple domains, making it impossible to define one universal baseURL

This forces developers to:

  • Manually strip origins from absolute URLs
  • Maintain complex mapping logic per backend domain
  • Duplicate normalization logic whenever new backends are added

Solution:
This PR makes the Cloudimage provider more resilient to real-world inputs by:

  1. Making baseURL optional: Only used when joining relative src paths
  2. Routing absolute URLs via CDN: All absolute src values are now consistently routed through the Cloudimage CDN base
  3. Simplified URL construction:
    • If src is absolute OR baseURL is missing: joinURL(CDN_BASE, src) + query
    • Otherwise: joinURL(CDN_BASE, baseURL, src) + query
  4. Improved dev warnings: Only warn when both token and cdnURL are missing (truly required inputs)

Changes:

  • src/runtime/providers/cloudimage.ts: Updated URL construction logic and made baseURL optional
  • docs/content/3.providers/cloudimage.md: Updated documentation to reflect new behavior
  • test/nuxt/providers.test.ts: Added test cases for absolute URLs and cdnURL-only scenarios

Backward Compatibility:

  • Existing configurations using token + baseURL continue to work unchanged
  • No breaking changes for current users
  • apiVersion behavior

@s8n11c s8n11c requested a review from danielroe as a code owner September 8, 2025 10:31
@vercel
Copy link

vercel bot commented Sep 8, 2025

@s8n11c is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 8, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/image@1951

commit: 1cfc184

@danielroe
Copy link
Member

would you have a look at the failing tests? 🙏

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.08%. Comparing base (282c6fd) to head (1cfc184).

Files with missing lines Patch % Lines
src/runtime/providers/cloudimage.ts 0.00% 5 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1951   +/-   ##
=====================================
  Coverage   7.08%   7.08%           
=====================================
  Files         76      76           
  Lines       3529    3529           
  Branches     137     137           
=====================================
  Hits         250     250           
  Misses      3232    3232           
  Partials      47      47           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielroe danielroe changed the title feat(provider/cloudimage): make baseURL optional and route absolute s… feat(cloudimage): make baseURL optional with cdn Sep 29, 2025
@danielroe danielroe merged commit 84cc49c into nuxt:main Sep 29, 2025
7 checks passed
@github-actions github-actions bot mentioned this pull request Sep 29, 2025
@ahmadalfy
Copy link

In real-world applications, image sources often come as full URLs from multiple backend services (CMS, DAM, microservices). The current Cloudimage provider has two main issues:

@danielroe I think the problem statement provided by @s8n11c should be the default for all the providers. Not just Cloudimage. This should be the default behavior for the module

@github-actions github-actions bot mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudimage: Absolute URLs bypass CDN and baseURL is required (friction with multi-origin backends)

4 participants