英文:
CORS problem with netlify APP (API URL endpoint)
问题
I just deployed my APP in netlify and it was working fine in development, I'm using netlify functions with faunadb, and when I run locally it all works. To make it work in production I just updated the API endpoint. To run locally I was using "http://localhost:8888/api/", and in production I changed to the URL provided by netlify. In production the App doesn't work, I get a CORS error like the image below, it occurs at the login section, when authenticating the user.
Axios instance with the URL (netlify URL + "/api/", as my /.netlify/functions/:splat in netlify.toml):
Function that calls netlify function:
netlify function (return part):
error that I'm getting:
英文:
I just deployed my APP in netlify and it was working fine in development, I'm using netlify functions with faunadb, and when I run locally it all works. To make it work in production I just updated the API endpoint. To run locally I was using "http://localhost:8888/api/", and in production I changed to the URL provided by netlify. In production the App doesn't work, I get a CORS error like the image below, it occurs at the login section, when authenticating the user.
I've already tried adding the headers configuration in the response of netlify function (image) and in netlify.toml file, but didn't work either. How can I configure this properly?
Axios instance with the URL (netlify URL + "/api/", as my /.netlify/functions/:splat in netlify.toml):
Function that calls netlify function:
答案1
得分: 0
看起来你拼错了 Access-Control-Allow-Origin
。
无论如何,CORS 头部应该由服务器返回,而不是由客户端发送。它应该作为对同一URL的预检 (OPTIONS) 请求的响应返回。
如果你的API正在使用ExpressJS,你可以在这里找到如何执行此操作的示例。
英文:
Looks like you misspelt Access-Control-Allow-Origin
.
In any event, the CORS headers need to be returned from the server, not sent by the client. It should be returned as a response to a pre-flight (OPTIONS) request at the same URL.
You can find an example of how to do this, if your API is using ExpressJS here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论