import cors from 'cors';
import { corsOptions } from '../../shared/cors/policy.js';

export const corsMiddleware = cors(corsOptions);

export function corsErrorHandler(err, req, res, next) {
  if (err && err.message === 'CORS not allowed') {
    return res.status(403).json({
      error: 'CORS not allowed',
      origin: req.get('Origin'),
    });
  }
  next(err);
}
