重定向到新的子域并在重定向的子域上设置cookie

时间: 2024-05-09 admin IT培训

重定向到新的子域并在重定向的子域上设置cookie

重定向到新的子域并在重定向的子域上设置cookie

Express:4.x

NodeJS:12.x

a.example上,我有一个GET侦听器,该侦听器重定向到b.example,并在b.example上设置cookie。

app.get('/foo', (req, res) => {
    res.cookie('name', 'foo', { domain: '.example', path: '/', secure: true })
    res.cookie('age', '21', { domain: '.example', path: '/', secure: true })
    res.redirect(302, '');
})

但是在b.example中未设置任何cookie。我在这里想念什么?

回答如下:

好,所以我想出了答案。从domain中删除res.cookie选项是有效的。