我正在尝试在我的 api 路由上启用 cors:
const server = Hapi.server({
port: 3003,
host: 'localhost',
routes: {
log: {
collect: true
},
cors: {
origin: ['http://localhost:8080'],
additionalHeaders: ['accept-language', 'accept-encoding', 'connection', 'origin', 'host', 'user-Agent', 'access-control-request-headers']
}
}
});
我添加了额外的标头,但它不会触发“Access-control-allow-origin 标头”的设置。
以下是请求标头:
host: 'localhost:3003',
connection: 'keep-alive',
'access-control-request-method': 'POST',
origin: 'http://localhost:8080',
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
'access-control-request-headers': 'x-access-token',
accept: '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7'
我错过了什么?谢谢。