CORS issues with Caddy and webhooks

Describe the problem/error/question

I made simple API in n8n and it works just fine from Postman. For a simple GET request it returns json.
I have VueJS app which calls this API.

What is the error message (if any)?

Browser blocks this call because it’s running on different domain.

Please share your workflow

It’s basically any webhook response.

What I tried

I’ve tried several Caddyfile variants, for example:

mydomain.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
header /webhook/* {
Access-Control-Allow-Origin https://vuejs-domain.com
Access-Control-Allow-Credentials true
Access-Control-Allow-Methods *
Access-Control-Allow-Headers *
defer
}
}

but with no luck

Information on your n8n setup

  • n8n version: 1.59.4
  • Database (default: SQLite): sqlite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker with caddy
  • Operating system: ubuntu 22.04 lts

Welcome to the community @blas !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.


You can try to fool the browsers by sending your JSON as plain text. For example,

  fetch(url, {
    method: 'POST',
    headers: {
        'Content-Type': 'text/plain'  // bypass CORS
    },
    body: JSON.stringify(request)
  })

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.