Fallback handler to requests outside of baseURL
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
When a custom baseURL is set, it is expected that all routes (and static assets) will be prefixed with {baseURL}/ so one should go to https://<addr>/{baseURL}.
If a request hits https://<addr>/* outside of {baseURL}, nitro renders a 404 because there is no route.
https://github.com/nitrojs/nitro/pull/2713 proposed a DX improvement to auto redirect /* to /{baseURL}* (only in dev) however it causes issues (https://github.com/nitrojs/nitro/issues/2881) as there are valid cases that a middleware or proxy route rule might actually need to handle this fallback.
In summary: This a nice DX but has downside of limiting some advanced cases and also potentially more mismatch behavior between dev and prod runtime behavior.
I am thinking of some progressive steps to handle:
- Improve dev error to show a hint that tells users it is 404 but hey, you might want need to go to this link.
- Add an opt-in option to enable baseURL redirect (in two modes: fallback|enforce)
- we should keep it opt-in for v2, we might enable by default for 3.0 however I'm not sure if trade-off worth it (if we do, we need clear docs about behavior and why/how opt-out)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing PR #2713 and issue #2881 to understand the rejected redirect behavior and its middleware or proxy conflicts. Define the intended development hint and the opt-in fallback and enforce modes, then verify that the chosen behavior preserves valid routes outside baseURL and is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100