mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(cli): Disable CORS on SSE connections in production (#4190)
This commit is contained in:
parent
bc42073e28
commit
e6e4f297c6
|
@ -1,13 +1,16 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import sseChannel from 'sse-channel';
|
import sseChannel from 'sse-channel';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
|
||||||
import { LoggerProxy as Logger } from 'n8n-workflow';
|
import { LoggerProxy as Logger } from 'n8n-workflow';
|
||||||
// eslint-disable-next-line import/no-cycle
|
|
||||||
import { IPushData, IPushDataType } from '.';
|
import { IPushData, IPushDataType } from '.';
|
||||||
|
|
||||||
|
interface SSEChannelOptions {
|
||||||
|
cors?: {
|
||||||
|
origins: string[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export class Push {
|
export class Push {
|
||||||
private channel: sseChannel;
|
private channel: sseChannel;
|
||||||
|
|
||||||
|
@ -16,13 +19,16 @@ export class Push {
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, new-cap
|
const options: SSEChannelOptions = {};
|
||||||
this.channel = new sseChannel({
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
cors: {
|
options.cors = {
|
||||||
// Allow access also from frontend when developing
|
// Allow access also from frontend when developing
|
||||||
origins: ['http://localhost:8080'],
|
origins: ['http://localhost:8080'],
|
||||||
},
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||||
|
this.channel = new sseChannel(options);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
this.channel.on('disconnect', (channel: string, res: express.Response) => {
|
this.channel.on('disconnect', (channel: string, res: express.Response) => {
|
||||||
|
|
Loading…
Reference in a new issue