Skip to content

Commit bfe59cf

Browse files
committed
fix: add same origin
1 parent f4ed72b commit bfe59cf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/config/cors.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ export default async (app) => {
66
const allowedOrigins = [
77
'http://localhost',
88
`http://localhost:${configService.get('PORT')}`,
9+
'http://metrix-api.vercel.app',
910
configService.get('CORS_ALLOWED_ORIGIN'),
1011
];
1112

13+
const errorMessage = 'Origin not allowed by CORS';
14+
1215
app.enableCors({
1316
credentials: true,
1417
origin: (origin: string, callback) => {
18+
if (!origin) callback(new Error(errorMessage));
19+
1520
const originIsWhitelisted = allowedOrigins.includes(origin);
1621
const originStartsOrEndsWithAllowed = allowedOrigins.some(
1722
(or) => origin.endsWith(or) || origin.startsWith(or),
1823
);
1924

20-
if (!origin || !originIsWhitelisted || !originStartsOrEndsWithAllowed) {
21-
callback(new Error('Origin not allowed by CORS'));
25+
if (!originIsWhitelisted || !originStartsOrEndsWithAllowed) {
26+
callback(new Error(errorMessage));
2227
}
2328

2429
callback(null, true);

0 commit comments

Comments
 (0)