Skip to content

Commit

Permalink
feat: enable cors
Browse files Browse the repository at this point in the history
  • Loading branch information
2paperstar authored Jun 23, 2024
1 parent b6fa342 commit 2b45c4b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import { ConfigService } from '@nestjs/config';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
// set CORS config
const whitelist = [
/https:\/\/.*gistalk.gistory.me/,
/https:\/\/.*gistalk-frontend.pages.dev/,
];
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,
});
// set swagger config
const config = new DocumentBuilder()
.setTitle('Gistalk API')
Expand Down

0 comments on commit 2b45c4b

Please sign in to comment.