From a3d59a24e39d689577f18eed1e4c06b652952c2f Mon Sep 17 00:00:00 2001 From: siwonpada Date: Mon, 18 Nov 2024 21:51:59 +0900 Subject: [PATCH] update: cors --- .vscode/settings.json | 1 + src/main.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index bb56588..3d84689 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "buildx", "dbdocs", "dbml", + "gistory", "gitops", "gsainfoteam", "infoteam", diff --git a/src/main.ts b/src/main.ts index 593b8c8..01a5a67 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,25 @@ import { ConfigService } from '@nestjs/config'; async function bootstrap() { const app = await NestFactory.create(AppModule); + // set CORS config + const whitelist = [ + /https:\/\/.*groups.gistory.me/, + /https:\/\/.*groups-fe.pages.dev/, + /http:\/\/localhost:3000/, + ]; + app.enableCors({ + origin: function (origin, callback) { + if (!origin || whitelist.some((regex) => regex.test(origin))) { + callback(null, origin); + } else { + callback(new Error('Not allowed by CORS')); + } + }, + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', + preflightContinue: false, + optionsSuccessStatus: 204, + credentials: true, + }); // load config service const configService = app.get(ConfigService); // swagger config