Skip to content

Commit

Permalink
[Feat] CORS with credentials support
Browse files Browse the repository at this point in the history
Enabled CORS with the front-end client.
References #17 and #21.
  • Loading branch information
angel-penchev committed Oct 23, 2021
1 parent ab0c86b commit ef5d92b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
const sessionRepository = getRepository(Session);

app.enableCors({
credentials: true,
origin: (origin, callback) => {
if (origin === configObject.client.root) {
return callback(null, true);
}
callback(new Error('Not allowed by CORS.'));
},
});
app.use(
session({
...configObject.session,
Expand Down

0 comments on commit ef5d92b

Please sign in to comment.