【问题标题】:hapi.js cors with authhapi.js cors 与 auth
【发布时间】:2017-11-19 23:18:04
【问题描述】:

把下面的放在一起。

server.route([
  {
    method: "POST",
    path: "/authorize",
    config: { 
      auth: false,
      cors: {
        origin: ['*']
      }
    },
    handler: (request, reply) => {
      ...
      reply.redirect(redirectUrl)
    }
  }
])

我想与客户端 JavaScript 浏览器获取 API 一起使用。 cors 部分是必要的,以避免对fetch 使用no-cors 模式并获得不透明的响应。 如果我只使用 'authin the config section or onlycors` 他们工作正常,但一起抱怨配置错误。

这是为什么呢?

【问题讨论】:

    标签: javascript hapijs


    【解决方案1】:

    config 对象内,您不能使用密钥cors。要正确配置,您必须像这样将cors 键放入其中

    server.connection({
      port: dbConfig.port,
      routes: { cors: true } // set cross origin by hapi inbuilt property
       // tls: tls
    })
    

    【讨论】:

      猜你喜欢
      • 2019-12-30
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 2017-04-11
      • 2020-02-12
      相关资源
      最近更新 更多