I am trying to enable CORS to connect my nestJS API with a local react app. But it seems that CORS is blocking access from the React App.
I've tries this so far:
First attempt:
async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
app.listen(3000);
}
bootstrap();
Second attempt:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
methods: ["GET", "POST"],
origin: '*',
})
app.listen(3000);
}
bootstrap();
And third attempt:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
methods: ["GET", "POST"],
origin: 'http://localhost:3001/',
})
app.listen(3000);
}
bootstrap();
Nothing of that seems to work.
The React app is just a simple superagent
call like this:
const res = sa.get(`http://localhost:3000/jokes/random`).withCredentials().end(res => console.log(res))
I've tried to use the superagent
with and without the withCredentials
.
Any idea of what is going on? thank you.