nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.28k stars 516 forks source link

proxy route rules in 2.10 dev server force append base URL #2881

Open wug-ge opened 1 week ago

wug-ge commented 1 week ago

Environment

node v22.11.0 nitropack@2.10.4 (error happens from 2.10.0 onwards)

Reproduction

Install new nitro project with version 2.10.x, add the following to nuxt.config.ts:

baseURL: '/app',

routeRules: { "/api/": { proxy: "http://localhost:3000/" }, },

Given it is just this few lines in a new project, I didn't make a reproduction. If you can't reproduce the issue, I'm happy to make one though. Be aware that "localhost:3000" is another local running server not nitro itself. My nitro project is running on localhost:3002. Please replace with any http server.

Describe the bug

With v2.9.7 if you add a baseURL like : /app and a routeRule like mentioned above, a request to /api/orders would correctly query http://localhost:3000/orders. Since 2.10.x this behavious has been changed and instead the following happens:

This might be intentional, but since it is a breaking change in a minor version I decided to report it here.

Additional context

I also opened the following issue in the Nuxt repo given I encountered the problem with Nuxt, but it is certainly nitro related after I tested it more: https://github.com/nuxt/nuxt/issues/29915

Logs

No response

pi0 commented 1 week ago

Minimal reproductions:

This is a regression from #2713 which only affects dev server proxies.

I think we should solve it by redoing #2713 as a 404 fallback handler instead.