Help with CORS problem with Edge Functions

I’m trying to make an Axios request from localhost to a netlify Edge Function and I get “Origin is not allowed by Access-Control-Allow-Origin. Status code: 200” error.

I have the following netlify.toml

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

    function = "login"
    path = "/login"

If I test it locally by running “netlify dev”, the header is set and it works. But if I build it, it doesn’t work.

This is my netlify build:

Can you help? Thank you!

Hey @cerpow

You’ll need to add the Access-Control-Allow-Origin header to the function return.


export default async () => {
  return new Response("OK", {
    headers: {
      'Allow-Access-Control-Origin': '*'
1 Like

Awesome! That worked!

It’s actually Access-Control-Allow-Origin but worked.
How can I set the header to res.json?

Thank you!

Do you mean the Content-Type header?

I mean context, sorry, it’s actually the same:

return ctx.json(
		{ message: 'hello'},
			headers: {
				'Access-Control-Allow-Origin': '*',

I believe this is what you are looking for.

export default async (req, ctx) => {
  let res = ctx.json({ msg: "hello" })
  res.headers.append('Allow-Access-Control-Origin', '*')
  return res

Yes, thank you very much!