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

Changed the way the headers are set

parent 8c86ad6c
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,7 @@ export const keys = {
public: '/etc/ssl/localcerts/cert.pem',
};
export const headers = {
'Access-Control-Allow-Origin': '*',
};
export const allowedOrigins = [ "*" ];
export const environment = (env.NODE_ENV ?? 'development') as ('development' | 'staging' | 'production');
import { NextFunction, Request, Response } from 'express';
import { headers } from './config';
import { allowedOrigins } from './config';
export function addDefaultHeaders(_req: Request, res: Response, next: NextFunction) {
let header : keyof typeof headers;
for (header in headers) {
res.header(header, headers[header]);
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);
}
next();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment