コルとヘッダーに問題があります。その後コルとヘッダー
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,X-Access-Token,Authorization');
next();
私はトークンをチェックするために、別のミドルウェアを持っている:私は、以下のミドルウェア持っ
const token = req.body.token || req.query.token || req.headers['x-access-token'];
if (token) {
jwt.verify(token, config.jwtKey, (err, decoded) => {
if(err) {
return res.json({success: false, errmsg: 'Wrong key'});
} else {
req.decoded = decoded;
next();
}
});
} else {
return res.status(403)
.send({
success: false,
message: "No token provided"
});
}
をしかし、私はreq.headersログインしたとき:
{ host: 'localhost:4556',
connection: 'keep-alive',
'access-control-request-method': 'POST',
origin: 'http://localhost:4200',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
'access-control-request-headers': 'authorization,content-type,x-access-token',
accept: '*/*',
dnt: '1',
referer: 'http://localhost:4200/posts',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'sv,en-US;q=0.8,en;q=0.6' }
のない「Xはありません「access-control-request-headers」を除いて、私のヘッダーに「-access-token」と書かれています。そしてそれはただの名前です。何かが間違っているはずですが、私がグーグルで見つけたのはAccess-Control-Allow-Headers
です。
res.set()を使用する必要がありますか?そして、価値と鍵は何が必要ですか? – gelv