Skip to content

feat(vercel): rewrite proxy route rule on cdn#4006

Merged
pi0 merged 5 commits intonitrojs:mainfrom
RihanArfan:feat/vercel-proxy-rewrites
Feb 6, 2026
Merged

feat(vercel): rewrite proxy route rule on cdn#4006
pi0 merged 5 commits intonitrojs:mainfrom
RihanArfan:feat/vercel-proxy-rewrites

Conversation

@RihanArfan
Copy link
Member

@RihanArfan RihanArfan commented Feb 6, 2026

🔗 Linked issue

Resolves #3484

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ 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

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@RihanArfan RihanArfan requested a review from pi0 as a code owner February 6, 2026 16:01
@vercel
Copy link

vercel bot commented Feb 6, 2026

@RihanArfan is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

This PR implements support for offloading proxy route rules to Vercel's CDN-level rewrites. It adds logic to determine which proxies are eligible for CDN handling, updates type definitions, modifies the build configuration generation, and includes documentation and tests demonstrating the feature with an external CDN proxy example.

Changes

Cohort / File(s) Summary
Type and implementation updates
src/presets/vercel/types.ts, src/presets/vercel/utils.ts
Updated VercelBuildConfigV3.routes type to support optional fields (dest, headers, continue, status). Added canUseVercelRewrite check to identify proxy rules eligible for CDN rewrites, UNSUPPORTED_PROXY_OPTIONS constant, and conditional CDN rewrite rule generation in generateBuildConfig.
Documentation
docs/2.deploy/20.providers/vercel.md
Added "Proxy route rules" section explaining CDN-level rewrites, eligibility criteria, unsupported proxy options, and the distinction between CDN-level and runtime proxies.
Tests and fixtures
test/fixture/nitro.config.ts, test/presets/vercel.test.ts, test/tests.ts
Added test fixture with "/cdn/**" proxy rule to CDN, corresponding Vercel preset route rule mapping, and a new "external proxy" test validating HTTP 200 status, ETag header presence, and response content from a CDN proxy request.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows conventional commits format with 'feat' type and scope, and clearly describes the main feature (Vercel CDN rewrites for proxy rules).
Description check ✅ Passed The PR description is related to the changeset, linking issue #3484 and indicating documentation and feature additions aligned with the code changes.
Linked Issues check ✅ Passed The PR implements all objectives from #3484: maps proxy rules to Vercel rewrites [#3484], adds CDN-level rewrite logic in utils.ts [#3484], documents the feature in vercel.md [#3484], and integrates into Vercel preset [#3484].
Out of Scope Changes check ✅ Passed All changes are within scope: documentation updates, type definitions for routes, proxy rewrite logic, test fixtures, and test cases directly support the Vercel CDN rewrites feature from #3484.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@4006

commit: ead819f

return false;
}
// Must be an external URL
if (!/^https?:\/\//.test(proxy.to.replace(/\/\*\*$/, ""))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: We could also use URL.canParse but this is also good!

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@pi0 pi0 changed the title feat(vercel): rewrite on cdn feat(vercel): rewrite proxy route rule on cdn Feb 6, 2026
@pi0 pi0 merged commit 241ef01 into nitrojs:main Feb 6, 2026
6 of 8 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/tests.ts`:
- Around line 547-554: The "external proxy" test calls callHandler which
performs a real network request and must be skipped when offline; update the
test block named "external proxy" to check process.env.OFFLINE (same pattern
used by other tests) and skip the test when that variable is set (e.g., use the
test.skip pattern or return early when OFFLINE is truthy) so the callHandler
network request is not executed in offline CI environments.

Comment on lines +547 to +554
it("external proxy", async () => {
const { data, headers, status } = await callHandler({
url: "/cdn/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js",
});
expect(status).toBe(200);
expect(headers["etag"]).toMatch(/W\/".+"/);
expect(data).toContain("Bootstrap");
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Test depends on external network access but lacks an OFFLINE skip guard.

This test makes a real HTTP request to cdn.jsdelivr.net. Other tests in this file (Line 752) already use process.env.OFFLINE to skip when network is unavailable. This test should do the same to avoid CI failures in offline/restricted environments.

Proposed fix
-  it("external proxy", async () => {
+  it.skipIf(!!process.env.OFFLINE)("external proxy", async () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("external proxy", async () => {
const { data, headers, status } = await callHandler({
url: "/cdn/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js",
});
expect(status).toBe(200);
expect(headers["etag"]).toMatch(/W\/".+"/);
expect(data).toContain("Bootstrap");
});
it.skipIf(!!process.env.OFFLINE)("external proxy", async () => {
const { data, headers, status } = await callHandler({
url: "/cdn/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js",
});
expect(status).toBe(200);
expect(headers["etag"]).toMatch(/W\/".+"/);
expect(data).toContain("Bootstrap");
});
🤖 Prompt for AI Agents
In `@test/tests.ts` around lines 547 - 554, The "external proxy" test calls
callHandler which performs a real network request and must be skipped when
offline; update the test block named "external proxy" to check
process.env.OFFLINE (same pattern used by other tests) and skip the test when
that variable is set (e.g., use the test.skip pattern or return early when
OFFLINE is truthy) so the callHandler network request is not executed in offline
CI environments.

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.

Use rewrites for handling proxy route rule in vercel

2 participants