Skip to content
Snippets Groups Projects
Commit 7d9a20ed authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Fixed the CORS headers if no origin is provided

parent d668fbe5
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,11 @@ import { allowedOrigins } from './config';
export function addDefaultHeaders(req: Request, res: Response, next: NextFunction) {
const origin = req.header('Origin');
if (allowedOrigins.includes('*') || origin && allowedOrigins.includes(origin)) {
res.header('Access-Control-Allow-Origin', origin);
if (origin) {
res.header('Access-Control-Allow-Origin', origin);
} else {
res.header('Access-Control-Allow-Origin', '*');
}
const headers = req.header('Access-Control-Request-Headers');
if (headers) {
res.header('Access-Control-Allow-Headers', headers);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment