Skip to content

Commit

Permalink
Bugfix/allow cors (#941)
Browse files Browse the repository at this point in the history
* Allowed vercel automatic branch deployments in CORS policy

* Reject non-origin requests
  • Loading branch information
MikaVohl authored Dec 7, 2024
1 parent 175271b commit 7e776fe
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@ if (!Services.env.isProduction()) {
credentials: true
};
} else {
// TODO: change this when necessary
corsOptions = {
origin: [
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
`https://docs.mchacks.ca`
],
origin: (origin, callback) => {
const allowedOrigins = [
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
`https://docs.mchacks.ca`
];

const regex = /^https:\/\/dashboard-[\w-]+\.vercel\.app$/;

if (
allowedOrigins.includes(origin) || // Explicitly allowed origins
regex.test(origin) // Matches dashboard subdomains
) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true
};
}



app.use(cors(corsOptions));
app.use(Services.log.requestLogger);
app.use(Services.log.errorLogger);
Expand Down

0 comments on commit 7e776fe

Please sign in to comment.