[英]Cors is configured in express.js but still error when post login credentials
i have configured cors headers in express js app login route as bellow:我在 express js 应用程序登录路由中配置了 cors 标头,如下所示:
106 app.post('/login', function(req, res, next) {
107 res.header('Access-Control-Allow-Credentials', true);
108 res.header('Access-Control-Allow-Origin', 'http://localhost:3100');
109 res.header('Access-Control-Allow-Methods', 'POST');
110 res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
111 passport.authenticate('local', function(err, user, info) {
112 res.send(info)
113 })(req, res, next);
114 });
I'm making this request:我提出这个要求:
const logIn = async (email, password) => {
try{
await axios.post('https://socialback.bieda.it/login', {email, password}, {withCredentials: true}).then((res)=> console.log(res.data));
} catch(e) {
console.log(e)
}
}
And i'm still getting cors error:而且我仍然收到 cors 错误:
Access to XMLHttpRequest at 'https://socialback.bieda.it/login' from origin 'http://localhost:3100' 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.
I'm googling this error but with no result, i have no idea what to do.我正在谷歌搜索这个错误,但没有结果,我不知道该怎么做。
What i tried我试过的
You have enabled CORS from http://localhost:3100
but you are calling https://socialback.bieda.it
from your client code您已从http://localhost:3100
启用 CORS 但您正在从您的客户端代码调用https://socialback.bieda.it
res.header('Access-Control-Allow-Origin', 'http://localhost:3100');
While your client sends a request to different server当您的客户端向不同的服务器发送请求时
await axios.post('https://socialback.bieda.it/login', {email, password}, {withCredentials: true}).then((res)=> console.log(res.data));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.