Hapijs cookie 未设置

Hapijs cookie not setting

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

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

然后在我的路线中我设置了 cookie "data" 和一些数据来测试它,像这样:

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

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

谢谢!

@devinivy 来自 https://gitter.im/hapijs/hapi 解释说:

isSecure tells the browser not to honor the cookie if there isn't a secured connection.

所以解决方案很简单,只要在不使用 HTTPS 时将 isSecure 设为 false(至少出于开发目的)。