Skip to content

Commit f7d5b91

Browse files
committed
feat(config): improve CORS config and whitelist handling
1 parent 2c59762 commit f7d5b91

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

server/src/config/cors.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const defaultOrigins = [
88
];
99

1010
const whitelist = process.env.ALLOWED_ORIGINS
11-
? process.env.ALLOWED_ORIGINS.split(',')
11+
? process.env.ALLOWED_ORIGINS.split(',').map(origin => origin.trim())
1212
: defaultOrigins;
1313

1414
export const corsConfig: CorsOptions = {
1515
origin: (origin, callback) => {
16-
if (!origin || whitelist.indexOf(origin) !== -1) {
16+
if (!origin || whitelist.includes(origin)) {
1717
callback(null, true);
1818
} else {
19-
callback(new Error(`Origin ${origin} not allowed by CORS`));
19+
callback(null, false);
2020
}
2121
},
2222
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],

0 commit comments

Comments
 (0)