Skip to content

Commit

Permalink
fix: cors
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Oct 22, 2024
1 parent 861c783 commit 266c598
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/server/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ export function setupSwagger(app: INestApplication): void {
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('/swagger', app, document);
app.getHttpAdapter().get('/', (req, res: FastifyReply) => {
void res.redirect(302, '/swagger');
void res.redirect('/swagger', 302);
});
}

export function enableCors(app: INestApplication): void {
app.enableCors({
origin: true,
origin: (requestOrigin, callback) => {
requestOrigin = requestOrigin.trim();
if (!requestOrigin || requestOrigin === 'null') {
callback(null, '*');
} else {
callback(null, requestOrigin);
}
},
credentials: false,
methods: ['OPTIONS', 'HEAD', 'GET', 'PUT', 'POST', 'DELETE'],
allowedHeaders: ['If-Match', 'If-None-Match', 'Content-Type', 'Authorization'],
Expand Down

0 comments on commit 266c598

Please sign in to comment.