報如下錯誤:
原因
設置signed: true后,它就會尋找req.secret(一個秘鑰字符串),進行加密 allen返回瀏覽器。
const SESS_CONFIG = {
key: 'kkb:sess',
maxAge: 86400000,
httpOnly: true,
signed: true,
};
app.use(session(SESS_CONFIG, app));
app.use(ctx => {
if (ctx.path === '/favicon.ico') return; let n = ctx.session.count || 0; ctx.session.count = ++n;
ctx.body = '第' + n + '次訪問';
});
解決辦法
增加代碼app.keys = ['some secret hurr'];
如下:
app.keys = ['some secret hurr'];
const SESS_CONFIG = {
key: 'kkb:sess',
maxAge: 86400000,
httpOnly: true,
signed: true,
};
app.use(session(SESS_CONFIG, app));
app.use(ctx => {
if (ctx.path === '/favicon.ico') return; let n = ctx.session.count || 0; ctx.session.count = ++n;
ctx.body = '第' + n + '次訪問';
});