# Node-RED template node + Traefik CORS problem

**URL:** https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359
**Category:** General
**Created:** [5 September 2022 17:13 UTC](https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359 "2022-09-05T17:13:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rucksman007](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@rucksman007](https://discourse.nodered.org/u/rucksman007)
#### Post date: [5 September 2022 17:13 UTC](https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359/1 "2022-09-05T17:13:13Z")

</div>

I am trying to load fonts from a subdomain different from the Node-RED subdomain in a template node, but this fails with this error:

```auto
Access to font at 'https://www.mydomain.tld/path/to/font.woff2' from origin 'https://node-red.mydomain.tld' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

```

I am running Node-RED from the official Docker image behind Traefik as a reverse proxy.

I tried to enable the CORS settings in settings.js like this:

```auto
httpNodeCors: {
    origin: "*",
    methods: "GET,PUT,POST,DELETE"
}

```

This did not help.

I also tried to put the following labels into my docker-compose.yml for Traefik:

```auto
- traefik.http.middlewares.cors.headers.accesscontrolalloworiginlist=*
- traefik.http.middlewares.cors.headers.accessControlAllowHeaders=*
- traefik.http.middlewares.cors.headers.accesscontrolallowmethods=GET,OPTIONS,PUT

```

And in my docker-compose.yml for Node\_RED:

```auto
- traefik.http.routers.nodered.middlewares=cors

```

No success. What would be a functioning solution?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 September 2022 19:07 UTC](https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359/2 "2022-09-05T19:07:47Z")

</div>

CORS is set by the endpoint server not the requester

In this case here, **you** are **requesting** from your browser to a **traefik server**

In simple terms, the issue is not with node-red but with the endpoint serving the data/resource/font - which in this case is traefik.

Search the net for "traefik CORS" - there are lots of threads, or head to the traefik forums.

---

<div class="post-metadata">

### Author: ![rucksman007](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@rucksman007](https://discourse.nodered.org/u/rucksman007)
#### Post date: [10 September 2022 11:55 UTC](https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359/3 "2022-09-10T11:55:51Z")

</div>

In case anyone else has this problem: Of course, it was an error on my part. Not Node-RED has to submit the relevant headers, but the other service (in my case a dockerized Apache webserver). Normally you do not need to change your Traefik configuration. I added this to the docker-compose.yml of my Apache container:

```auto
labels:
    # CORS for Node-RED
    - "traefik.http.routers.webserver-https.middlewares=cors"
    - "traefik.http.middlewares.cors.headers.accesscontrolallowmethods=GET,OPTIONS,POST"
    - "traefik.http.middlewares.cors.headers.accesscontrolmaxage=100"
    - "traefik.http.middlewares.cors.headers.addvaryheader=true"
    - "traefik.http.middlewares.cors.headers.accessControlAllowOriginList=https://node-red.mydomain.tld"

```

If you do not want to explicitely name the domains, you can use a wildcard. But for whatever reason, this line did NOT work for me:

```auto
- "traefik.http.middlewares.cors.headers.accessControlAllowOriginList=*"

```

But kind of a dirty trick did work:

```auto
- "traefik.http.middlewares.cors.headers.accessControlAllowOriginListRegex=(.*?)"

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 November 2022 11:56 UTC](https://discourse.nodered.org/t/node-red-template-node-traefik-cors-problem/67359/4 "2022-11-09T11:56:30Z")

</div>

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