Configure CORS pre-flight request (OPTION method)

I am trying to use n8n as the backend for a simple, static single page “application”. For now, it’s basically a form. I am posting stuff with Javascript fetch API and have trouble receiving the data. My idea is to have the frontend hosted anywhere, its static so can be GitHub pages or wherever. I host n8n myself (in Docker).Thus I need CORS, as the frontend and backend are on different domains.

I set it up as follows in the frontend:

const reply = await fetch(API_URL, {
  method: "POST",
  mode: "cors",
  headers: new Headers({
    "Content-Type": "application/json"
  }),
  body: JSON.stringify(data)
});

The problem as I’ve understood it, is that the pre-flight is done as an OPTION request. This method/verb isn’t configurable in the Webhook node in n8n, so I can’t reply with proper headers to allow the request.

Is it possible to expose the OPTION method to the Webhook node? I could then have two webhook triggers in a workflow: one for OPTION replying with CORS stuff, the other one for POST actually accepting the pre-flighted payload. Or am I missing something?

Information on your n8n setup

  • n8n version: 1.0.0-rc
  • Database Postgres 15.1
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via: Docker
  • Operating system: Windows 10