nest: CORS does not seem to activate
I’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
CORS simply does not work regardless of how I enable it.
const app = await NestFactory.create(AppModule, { cors: true });const app = await NestFactory.create(AppModule, { cors: {corsOptions} });app.enableCors() ;app.enableCors({corsOptions})app.use(cors());
HTTP OPTIONS requests just end up with a 404
This is during development and not production. I’ve checked whether or not compiling to javascript was successful as well.
Expected behavior
CORS should be enabled.
Minimal reproduction of the problem with instructions
Create a new project and just attempt to enable CORS with previously mentioned methods above.
What is the motivation / use case for changing the behavior?
Environment
Nest version: 5.3.10
For Tooling issues:
- Node version: 10.6.0
- Platform: Windows 7, MacOS 10.14
Others:
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 34 (5 by maintainers)
these codes are not working again in version nestjs@6.0.4
Issue still here, tried everything from above.
Same issue debugging from Ionic, Web and Mobile:
I have the same issue as @tskweres. Currently developing a mobile app using nest and ionic. When my Ionic app is deployed on my phone, it can’t communicate with my NestJS server on the same WIFI network. Tried to access my server URL directly on my phone’s browser, it doesn’t work.
I have tested various cors origin configurations such as
*,/.+/, and my phone’s IP address, but nothing seems to work.It seems the following code works. But passing CorsOptions obj or use app.enableCors(options) won’t work. When the browse try to run OPTIONS method, nestjs spits 404 error.
Please share the repo, I can not reproduce the issue either.
No. I’m probably testing it incorrectly. Let me do more homework and possibly reopen