Skip to content

Commit

Permalink
update: cors
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Nov 18, 2024
1 parent 8864b67 commit a3d59a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"buildx",
"dbdocs",
"dbml",
"gistory",
"gitops",
"gsainfoteam",
"infoteam",
Expand Down
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3d59a2

Please sign in to comment.