You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the backend code which has the proxy in it (it is a dotnet app in this sample)
Try to access a route that Next js file structure has, for example here /home (either on localhost:3000 or the backend localhost) a sample "http://localhost:3000/home"
You will notice the console.log in the home page is invoked before the middleware and everything in the page is being read
The middleware will be invoked and will return what you are looking for (in this case I am just rewriting to 404 page)
Also you will see that the middleware is being invoked multiple times for the same route along side the /home request
Current vs. Expected behavior
This behavior started after upgrading next to 14.2.3, before the upgrade I was working on next 14.0.3 and this issue did not occur. The middleware was being invoked first and everything worked normal.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Enterprise
Available memory (MB): 20323
Available CPU cores: 8
Binaries:
Node: 18.18.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.3.0-canary.59 // Latest available version is detected (14.3.0-canary.59).
eslint-config-next: N/A
react: 19.0.0-beta-4508873393-20240430
react-dom: 19.0.0-beta-4508873393-20240430
typescript: 5.1.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
I have tested it in the latest canary version 14.3.0-canary.59 and the issue still exists.
Please be aware that the issue disappears when you remove this environment variable NODE_TLS_REJECT_UNAUTHORIZED=0
According to my knowledge this issue occurs when you have proxy + middleware + the API in the middleware returns 404 + having the environment variable mentioned above.
*Update
When I made the API as an HTTP instead of HTTPS and remove the environment variable NODE_TLS_REJECT_UNAUTHORIZED=0 the same issue happens. So probably the issue comes with proxy + middleware + API in the middleware returns 404 or so
**Update 2
When the API returns not found with empty response instead not found with HTML response, the issue is resolved
The text was updated successfully, but these errors were encountered:
Link to the code that reproduces this issue
https://github.com/AnasArafeh/Next14.2.3-Middleware-with-proxy-issue
To Reproduce
Current vs. Expected behavior
This behavior started after upgrading next to 14.2.3, before the upgrade I was working on next 14.0.3 and this issue did not occur. The middleware was being invoked first and everything worked normal.
Provide environment information
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
I have tested it in the latest canary version 14.3.0-canary.59 and the issue still exists.
Please be aware that the issue disappears when you remove this environment variable NODE_TLS_REJECT_UNAUTHORIZED=0
According to my knowledge this issue occurs when you have proxy + middleware + the API in the middleware returns 404 + having the environment variable mentioned above.
*Update
When I made the API as an HTTP instead of HTTPS and remove the environment variable NODE_TLS_REJECT_UNAUTHORIZED=0 the same issue happens. So probably the issue comes with proxy + middleware + API in the middleware returns 404 or so
**Update 2
When the API returns not found with empty response instead not found with HTML response, the issue is resolved
The text was updated successfully, but these errors were encountered: