I am unable to enable CORS for NestJs for development, using most of the built-in methods in main.hmr.ts as follows:
const app = await NestFactory.create(AppModule, { cors: true });
const app = await NestFactory.create(AppModule, { cors: { corsOptions... } });
app.enableCors() ;
app.enableCors({ corsOptions.. });
app.use(cors());
app.use( (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Origin', 'Content-Type, Accept');
} );
It feels like everything I'm doing in main.hmr.ts is just being ignored.
The only thing that works is using the @Header decorator i.e. @Header('Access-Control-Allow-Origin', '*') within the controllers.
This is ok as a temporary measure, during development but it's not ideal long term.
I've checked the compiled javascript, and it seems fine. I tried this both on Windows and MacOS; same issue. What did I potentially do wrong?