将以下内容放在一起。
server.route([
{
method: "POST",
path: "/authorize",
config: {
auth: false,
cors: {
origin: ['*']
}
},
handler: (request, reply) => {
...
reply.redirect(redirectUrl)
}
}
])
我想与客户端 JavaScript 浏览器 fetch API 一起使用。 cors
部分是必要的,以避免使用 no-cors
模式进行 fetch
并获得非不透明的响应。
如果我在配置部分仅使用 'auth 或仅使用
cors`,它们工作正常,但一起 hapi 提示配置错误。
这是为什么?
最佳答案
在config
对象中,您不能使用键cors
。为了正确配置,您必须将 cors
键放入其中,如下所示
server.connection({
port: dbConfig.port,
routes: { cors: true } // set cross origin by hapi inbuilt property
// tls: tls
})
关于javascript - hapi.js 与 auth 相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47307529/