mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-08 11:27:30 -08:00
19 lines
660 B
TypeScript
19 lines
660 B
TypeScript
|
import type { RequestHandler } from 'express';
|
||
|
|
||
|
const { NODE_ENV } = process.env;
|
||
|
const inDevelopment = !NODE_ENV || NODE_ENV === 'development';
|
||
|
|
||
|
export const corsMiddleware: RequestHandler = (req, res, next) => {
|
||
|
if (inDevelopment && 'origin' in req.headers) {
|
||
|
// Allow access also from frontend when developing
|
||
|
res.header('Access-Control-Allow-Origin', req.headers.origin);
|
||
|
res.header('Access-Control-Allow-Credentials', 'true');
|
||
|
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
||
|
res.header(
|
||
|
'Access-Control-Allow-Headers',
|
||
|
'Origin, X-Requested-With, Content-Type, Accept, sessionid',
|
||
|
);
|
||
|
}
|
||
|
next();
|
||
|
};
|