Support Forums

I'm unable to set CORS header on POST/GET request to API on Netlify Functions


I have deployed https://analytics.growthfyi.com on Netlify (Ackee Analytics), now when I use it on https://www.growthfyi.com, it shows CORS error.

I don’t know why /api isn’t showing CORS header whereas I have already added that via netlify.toml

Here is my Netlify.toml file

  publish = "dist"
  command = "yarn build"
  functions = "functions/"
  environment = { NODE_VERSION = "14.9.0", NODE_ENV = "production" }
  from = "/api"
  to = "/.netlify/functions/api"
  status = 200
  force = true
  headers = {Access-Control-Allow-Origin= "*"}

  for = "/*"
    Access-Control-Allow-Origin= "*"


I can see CORS on my landing page https://analytics.growthfyi.com and https://analytics.growthfyi.com/tracker.js but not on /api which is managed by Netlify functions.

Hi @kaknut,

To resolve your issue, your function itself will need to have that header as part of the response object that your function returns. You won’t be able to inject it via a redirect or header rule. Let me know if that helps.