File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Expand file tree Collapse file tree 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()) {
4343 credentials : true
4444 } ;
4545} else {
46- // TODO: change this when necessary
4746 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+ } ,
5365 credentials : true
5466 } ;
5567}
5668
69+
70+
5771app . use ( cors ( corsOptions ) ) ;
5872app . use ( Services . log . requestLogger ) ;
5973app . use ( Services . log . errorLogger ) ;
You can’t perform that action at this time.
0 commit comments