File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,24 @@ export default async (app) => {
6
6
const allowedOrigins = [
7
7
'http://localhost' ,
8
8
`http://localhost:${ configService . get ( 'PORT' ) } ` ,
9
+ 'http://metrix-api.vercel.app' ,
9
10
configService . get ( 'CORS_ALLOWED_ORIGIN' ) ,
10
11
] ;
11
12
13
+ const errorMessage = 'Origin not allowed by CORS' ;
14
+
12
15
app . enableCors ( {
13
16
credentials : true ,
14
17
origin : ( origin : string , callback ) => {
18
+ if ( ! origin ) callback ( new Error ( errorMessage ) ) ;
19
+
15
20
const originIsWhitelisted = allowedOrigins . includes ( origin ) ;
16
21
const originStartsOrEndsWithAllowed = allowedOrigins . some (
17
22
( or ) => origin . endsWith ( or ) || origin . startsWith ( or ) ,
18
23
) ;
19
24
20
- if ( ! origin || ! originIsWhitelisted || ! originStartsOrEndsWithAllowed ) {
21
- callback ( new Error ( 'Origin not allowed by CORS' ) ) ;
25
+ if ( ! originIsWhitelisted || ! originStartsOrEndsWithAllowed ) {
26
+ callback ( new Error ( errorMessage ) ) ;
22
27
}
23
28
24
29
callback ( null , true ) ;
You can’t perform that action at this time.
0 commit comments