File tree 1 file changed +20
-6
lines changed
1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -43,17 +43,31 @@ if (!Services.env.isProduction()) {
43
43
credentials : true
44
44
} ;
45
45
} else {
46
- // TODO: change this when necessary
47
46
corsOptions = {
48
- origin : [
49
- `https://${ process . env . FRONTEND_ADDRESS_DEPLOY } ` ,
50
- `https://${ process . env . FRONTEND_ADDRESS_BETA } ` ,
51
- `https://docs.mchacks.ca`
52
- ] ,
47
+ origin : ( origin , callback ) => {
48
+ const allowedOrigins = [
49
+ `https://${ process . env . FRONTEND_ADDRESS_DEPLOY } ` ,
50
+ `https://${ process . env . FRONTEND_ADDRESS_BETA } ` ,
51
+ `https://docs.mchacks.ca`
52
+ ] ;
53
+
54
+ const regex = / ^ h t t p s : \/ \/ d a s h b o a r d - [ \w - ] + \. v e r c e l \. a p p $ / ;
55
+
56
+ if (
57
+ allowedOrigins . includes ( origin ) || // Explicitly allowed origins
58
+ regex . test ( origin ) // Matches dashboard subdomains
59
+ ) {
60
+ callback ( null , true ) ;
61
+ } else {
62
+ callback ( new Error ( 'Not allowed by CORS' ) ) ;
63
+ }
64
+ } ,
53
65
credentials : true
54
66
} ;
55
67
}
56
68
69
+
70
+
57
71
app . use ( cors ( corsOptions ) ) ;
58
72
app . use ( Services . log . requestLogger ) ;
59
73
app . use ( Services . log . errorLogger ) ;
You can’t perform that action at this time.
0 commit comments