Closed nils-jansen closed 2 years ago
It just worked again, no changes to backend or frontend:
btw when you call enableCors
, NestJS just attaches the cors()
middleware. So you should report on their repo
That would just be a guess though. Could it be that the middleware is somehow not attached by error? What would be the best way to debug this?
Could it be that the middleware is somehow not attached by error?
I'd say: probably not as that this.use(cors(options))
will invoke expressAppInstance.use(cors(options))
directly, so there's no nestjs-specific stuff here
Thus I believe you could rely on expressjs debugging tips to debug that (you can access the underlying expressAppInstance
via app.getHttpAdapter().getInstance()
). I've been using app.enableCors({ origin })
with no worries so far
It just worked again, no changes to backend or frontend
then you problably was running an old version of your backend (or there is some bug on nestjs side, of course)
I debugged Express directly (https://expressjs.com/en/guide/debugging.html) and found out that the browser does not make any request at all, event though it is showing me a 404 with response headers and body in the dev console. Spooky stuff, will investigate further. Thanks for your help @micalevisk !
Is there an existing issue for this?
Current behavior
When sending a PATCH request from the frontend (localhost:3000) to my backend (localhost:5000), the browser sends a preflight OPTIONS request to the backend which fails with 404:
In main.ts:
Minimum reproduction code
n/a
Steps to reproduce
I can't reproduce this deterministically as it happens only sporadically :(
Expected behavior
No CORS Error in browser
Package
Other package
No response
NestJS version
8.0.0
Packages versions
Node.js version
16.13
In which operating systems have you tested?
Other
This might not be a bug with NestJS, I just don't know how to debug this properly. I can't provide a useful reproduction because the issue only appears sporadically - one day it works, the next day it doesn't. I must be missing something. I've tried multiple browsers, same issue everywhere. I've deleted the dist/ folder before starting the server, didn't help.