使用Nodej进行身份验证期间的不同数量会话
我读这篇文章on Medium我来到了它写的会议数量link on Pastbin
在这篇文章中写道,经过多次调用这个命令“client $ curl -X GET http://localhost:3000 -b cookie-file.txt”,我必须得到一个相同的结果。但在输出中我有
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
f559ee33-2928-41a0-94aa-39025578cbc6
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
fcc48f22-2000-44f5-8f19-13adb1bf8191
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
dc696106-10ea-413a-b60e-b1e725820311
我不明白为什么我会得到不同的号码会话。
回答如下:试试这个:
app.use((req, res, next) => {
req.session.init = "initProgram"; //this is very important for sessions, we need to initialize it for authentication.
next();
});
每次调用路由时,都会创建一个新会话。当您调用http://localhost:3000时,初始化会话,然后在后续调用中使用cookie仅使用该会话。
使用Nodej进行身份验证期间的不同数量会话
我读这篇文章on Medium我来到了它写的会议数量link on Pastbin
在这篇文章中写道,经过多次调用这个命令“client $ curl -X GET http://localhost:3000 -b cookie-file.txt”,我必须得到一个相同的结果。但在输出中我有
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
f559ee33-2928-41a0-94aa-39025578cbc6
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
fcc48f22-2000-44f5-8f19-13adb1bf8191
Inside the session middleware
de5b7edc-09e7-47dc-b9f8-8ac0179ec1ea
Inside the homepage callback function
dc696106-10ea-413a-b60e-b1e725820311
我不明白为什么我会得到不同的号码会话。
回答如下:试试这个:
app.use((req, res, next) => {
req.session.init = "initProgram"; //this is very important for sessions, we need to initialize it for authentication.
next();
});
每次调用路由时,都会创建一个新会话。当您调用http://localhost:3000时,初始化会话,然后在后续调用中使用cookie仅使用该会话。