mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Add Support for custom CORS origins for webhooks (#7455)
node-850 https://community.n8n.io/t/add-ability-to-set-cors-allow-list-in-n8n-webhooks/7610 https://community.n8n.io/t/configure-cors-pre-flight-request-option-method-in-the-roadmap/32189 --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -1594,7 +1594,8 @@ export interface INodeTypeDescription extends INodeTypeBaseDescription {
|
||||
properties: INodeProperties[];
|
||||
credentials?: INodeCredentialDescription[];
|
||||
maxNodes?: number; // How many nodes of that type can be created in a workflow
|
||||
polling?: boolean;
|
||||
polling?: true | undefined;
|
||||
supportsCORS?: true | undefined;
|
||||
requestDefaults?: DeclarativeRestApiSettings.HttpRequestOptions;
|
||||
requestOperations?: IN8nRequestOperations;
|
||||
hooks?: {
|
||||
|
||||
@@ -236,7 +236,7 @@ export const cronNodeOptions: INodePropertyCollection[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const specialNodeParameters: INodeProperties[] = [
|
||||
const commonPollingParameters: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Poll Times',
|
||||
name: 'pollTimes',
|
||||
@@ -252,12 +252,28 @@ const specialNodeParameters: INodeProperties[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const commonCORSParameters: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Allowed Origins (CORS)',
|
||||
name: 'allowedOrigins',
|
||||
type: 'string',
|
||||
default: '*',
|
||||
description: 'The origin(s) to allow cross-origin non-preflight requests from in a browser',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Apply special parameters which should be added to nodeTypes depending on their type or configuration
|
||||
*/
|
||||
export function applySpecialNodeParameters(nodeType: INodeType): void {
|
||||
if (nodeType.description.polling === true) {
|
||||
nodeType.description.properties.unshift(...specialNodeParameters);
|
||||
const { properties, polling, supportsCORS } = nodeType.description;
|
||||
if (polling) {
|
||||
properties.unshift(...commonPollingParameters);
|
||||
}
|
||||
if (nodeType.webhook && supportsCORS) {
|
||||
const optionsProperty = properties.find(({ name }) => name === 'options');
|
||||
if (optionsProperty) optionsProperty.options!.push(...commonCORSParameters);
|
||||
else properties.push(...commonCORSParameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user