Access to fetch at 'https://website-dev.netlify.app/.netlify/functions/checkout' from origin 'http://dev.website.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Is it possible to send a fetch request cross domain to a netlify lambda function I get the following error
Access to fetch at âhttps://website-dev.netlify.app/.netlify/functions/stripe-checkout-session-fixâ from origin âhttp://dev.website.comâ has been blocked by CORS policy: Response to preflight request doesnât pass access control check: No âAccess-Control-Allow-Originâ header is present on the requested resource. If an opaque response serves your needs, set the requestâs mode to âno-corsâ to fetch the resource with CORS disabled.
[build]
functions ="functions/"
[[headers]]
# Define which paths this specific [[headers]] block will cover.
for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"
Youâll also want to allow the OPTION method as well, since that is the first request by the browser to determine if the request is allowed before doing a GET or POST. Let me know how that goes.
I added like so
âAccess-Control-Allow-Methodsâ: âGET, POST, OPTIONâ,
but am still gettign the error But in the error it is complaining about the Access-Control-Allow-Origin, and I have that in the lambda and the netlify.toml
Your function, not your html, would need that header. The custom headers functionality WILL NOT apply to functions; only what your function returns can add headers there.
Seems like youâve removed that function in the meantime - did you abandon or did you end up implementing differently?
That looks right to me! At this point, Iâd start playing with things that seem like they shouldnât matter but might: move headers above body in the response, try single quotes instead of double, etc.