Preflight CORS won't work from page

Hi

I setup a Function that sends a email. I call this function from my Vue client that is hosted somewhere else then Netlify, or more correctly at this stage it’s localhost. So to the problem I have is preflight CORS error.

Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

So it works with Postman as that cruises by the CORS but it’s totally impossible to get this to work from a webpage.

My header declaration looks like this with the preflight and headers, what am I doing wrong? Let me know if you need anything from me like account number ect.

const headers = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "Content-Type",
  "Access-Control-Allow-Methods": "POST, OPTIONS",
}

if (event.httpMethod === 'OPTIONS') {
  console.log('options: preflight test CORS')

  return {
    statusCode: '204',
    headers
  }
}

Hey there! This might be a localhost nuance. Check this out for more info, provided kindly by our very own Netlify Pilot @talves!

1 Like

Hi,

Thanks for the answer. However it did not solve it. Also I’m not sure what part I should grab from that stackoverflow answer? That specific issue is formatting related and mine is not. I tried now from the live domain and get the same error with preflight. Any other ideas, do you need anything else from me, like account id, code?

Yes, please! A link to the function would be handy, or the site app ID and function name, or another means of identifying the function!

Thanks :slightly_smiling_face:

site app id:
elegant-newton-8397f8

function name:
send-email

Hey there,

Nothing looks glaringly wrong to me I’m afraid. Have you seen this lengthy discussion which may give you some pointers? Maybe this in particular, which will need this to remediate it?

1 Like