Skip to content

Commit 2fe39a1

Browse files
committed
Add configuration for CORS
1 parent 59b6f7a commit 2fe39a1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backend/src/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ async function bootstrap() {
1010
const configService = app.get(ConfigService);
1111
const port = configService.get<number>('port') ?? 3000;
1212

13+
// Enable CORS
14+
app.enableCors({
15+
origin: [
16+
'http://localhost:5173', // Vite default dev server
17+
'http://localhost:3000',
18+
'http://localhost:4173', // Vite preview
19+
...(process.env.FRONTEND_URL ? [process.env.FRONTEND_URL] : []),
20+
],
21+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
22+
credentials: true,
23+
});
24+
1325
// Add global prefix 'api' to all routes
1426
app.setGlobalPrefix('api');
1527

0 commit comments

Comments
 (0)