【问题标题】:Hapijs cookie not settingHapijs cookie 未设置
【发布时间】:2016-06-05 04:22:06
【问题描述】:

我阅读了Hapijs's guide on cookies 并尝试实现它。在我的主 index.js 文件中,我按照建议放置了配置:

server.state('data', {
    ttl: null,
    isSecure: true,
    isHttpOnly: true,
    encoding: 'base64json',
    clearInvalid: false,
    strictHeader: true
});

然后在我的路线中,我使用一些数据设置 cookie“数据”来测试它,如下所示:

{
    method: 'POST',
    path: '/create',
    handler: function (request, reply) {
        reply('hello').state('data', { firstVisit: true });
    }
}

当我在 chrome 调试工具中检查 cookie 时,它​​没有显示 cookie。奇怪的是它确实回复了 hello 并且它也没有输出任何错误。有人知道我做错了什么吗?

谢谢!

【问题讨论】:

    标签: node.js cookies hapijs


    【解决方案1】:

    来自https://gitter.im/hapijs/hapi 的@devinivy 解释了它:

    isSecure 告诉浏览器在没有安全连接时不要使用 cookie。

    所以解决方案就像在不在 HTTPS 上时将 isSecure 设置为 false 一样简单(至少出于开发目的)。

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 2014-10-10
      • 2018-06-22
      • 2021-10-21
      • 2012-02-11
      • 2016-02-12
      • 2011-11-03
      相关资源
      最近更新 更多