fix(vite): remove extension check to support dotted API routes#3994
fix(vite): remove extension check to support dotted API routes#3994kricsleo wants to merge 1 commit intonitrojs:mainfrom
Conversation
|
@kricsleo is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughModified the Vite dev middleware to add a 404 fallback mechanism that delegates unhandled requests to the next middleware (allowing Vite to process them) and removed extension-based filtering that previously blocked extension-less URLs from reaching the Nitro/dev pipeline. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/build/vite/dev.ts`:
- Around line 225-229: The handler that checks envRes.status === 404 should not
reset nodeReq._nitroHandled because that lets the request be processed again by
nitroDevMiddleware; instead, remove the line that sets nodeReq._nitroHandled =
false and simply call next() so Vite can handle the fallback while leaving the
Nitro-handled flag intact (change the branch in the envRes.status === 404 block
that references nodeReq._nitroHandled and next()).
| if (envRes.status === 404) { | ||
| // Allow Vite to try | ||
| nodeReq._nitroHandled = false; | ||
| return next(); | ||
| } |
There was a problem hiding this comment.
Avoid re-running Nitro middleware after 404 fallback.
Resetting nodeReq._nitroHandled allows the same request to hit the later nitroDevMiddleware (registered at the end), duplicating Nitro dispatch for 404s. Keeping the flag set still lets Vite handle via next().
🔧 Suggested change
if (envRes.status === 404) {
// Allow Vite to try
- nodeReq._nitroHandled = false;
return next();
}📝 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.
| if (envRes.status === 404) { | |
| // Allow Vite to try | |
| nodeReq._nitroHandled = false; | |
| return next(); | |
| } | |
| if (envRes.status === 404) { | |
| // Allow Vite to try | |
| return next(); | |
| } |
🤖 Prompt for AI Agents
In `@src/build/vite/dev.ts` around lines 225 - 229, The handler that checks
envRes.status === 404 should not reset nodeReq._nitroHandled because that lets
the request be processed again by nitroDevMiddleware; instead, remove the line
that sets nodeReq._nitroHandled = false and simply call next() so Vite can
handle the fallback while leaving the Nitro-handled flag intact (change the
branch in the envRes.status === 404 block that references nodeReq._nitroHandled
and next()).
commit: |
🔗 Linked issue
resolves #3990
❓ Type of change
📚 Description
Removed overly broad extension check that broke routes like
/api/foo.get. Added404fallback to Vite instead.📝 Checklist