allow-origins.ts

import {
  DOMAIN_HOSTING_LOCAL,
  DOMAIN_NAME_PPP,
  DOMAIN_NAME_PROD
} from '../../config/constants';

export function allowOrigins(req, res, next) {
  const allowedOrigins = [
    DOMAIN_NAME_PROD,
    DOMAIN_HOSTING_LOCAL,
    DOMAIN_NAME_PPP
  ];
  const origin = req.headers.origin;
  if (allowedOrigins.includes(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
  }
  next();
}