英文:
CORS error while trying to register on my app
问题
我是新来到Node.js和后端编程世界的,我遇到了CORS错误。
我已经尝试了很多解决方案,但没有一个对我起作用。
我正在使用fly.io作为服务器。
在我的代码中,我已经有了这个:
const cors = require('cors');
const app = express();
app.use(cors());
另外,当我点击注册时,也会出现这一行:
2023/07/06 - 16:29:39 | 404 | 910ns | 92.188.66.18 | OPTIONS /register
(注意:在本地主机上使用nodemon时,注册代码工作得很好)有人有解决方案吗?
英文:
I'm new to the world of node.js and backend programmation, and i have a CORS error.
i already tried a lot of solutions, but nothing worked for me.
I'm using fly.io as server.
Acess to fetch at 'https://<MYFLY.IO URL>/register' from origin 'http://localhost:19006' 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.
in my code, i already have this :
const cors = require('cors');
const app = express();
app.use(cors());
also, i have this line that shows up when i click register :
2023/07/06 - 16:29:39 | 404 | 910ns | 92.188.66.18 | OPTIONS /register
(note : the register code worked well on localhost with nodemon)
Do someone have a solution ?
答案1
得分: 0
实际上,只有在这个本地地址上它不想工作。我尝试使用Expo Go构建我的应用程序,当我尝试注册时,它不会显示CORS错误。那么,问题解决了吗?嗯,现在我有另一个问题,但我不能在这里发布我的问题,因为它不是相同的目的。
英文:
so in fact, there is only with this localhost adress that it doesn't want to work. I tried building my app with expo go, and when i try to register, it doesn't show the CORS error. So, probleme solved ? well, i have another problem now, but i can't post my question here because it is not the same purpose.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论