CORS error when accessing using localhost

Describe the problem/error/question

I’m trying to fetch user workflows using Rest Endpoint hosted in our own server. I’m using localhost for development however I’m getting CORS error. Is it possible to use localhost to use n8n endpoints? Or do we need to develop our own API to call n8n endpoint, fetch workflows and return it to the frontend client?

What is the error message (if any)?

CORS error

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @wardo1230, welcome to the community!

I am sorry to hear you’re having trouble.

n8n doesn’t have built-in logic avoiding CORS issues, so you’d want to add the required headers outside of n8n itself. Typically on a reverse proxy level as suggested over here for nginx (this topic is about the webhook node, but the basic idea should work for other browser-initiated requests subject to CORS as well of course).


Hi @MutedJam thanks for the information. However, we did try the solution you’ve linked to but still got no luck.

Also, we’ve already tried to serve n8n locally. Here is my docker-compose file

version: "3"

    image: "traefik"
    restart: always
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - ""
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "${SSL_EMAIL}"
      - ""
      - "80:80"
      - "443:443"
      - /var/run/docker.sock:/var/run/docker.sock:ro

    restart: always
      - ""
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
      - traefik.frontend.headers.customResponseHeaders=Access-Control-Allow-Origin:*
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production

What we currently get is error 204 No Content even if the request is from localhost to localhost (n8n). Is there possibly something that I’ve missed? Thanks!

Hey @wardo1230,

Are you still seeing the cors message as well? That will typically help show what needs to be changed in the reverse proxy configuration.