var express = require('express') , cookieParser = require('cookie-parser') , session = require('cookie-session') , express_sess = require('express-session') , app = express();//====================================================app.use(cookieParser())// app.use(session({ keys: ['abc'], name: 'user' }));// {}// { 'connect.sid': 's:cpI6_ewOlAoRIl0kGkwRVOOZAQnA0n_t.9Q1cv7SP1ADoHArxmqtqQEEXyQE// fRjaWxsXnQTY4bLI' }//====================================================app.use(express_sess({ secret: 'abc', key: 'user'}));// req.session: { cookie: { // path: '/',// _expires: null,// originalMaxAge: null,// httpOnly: true // } // }// req.cookie: {user: 's:aJ97vKA5CCwxqdTj0AV1siRQ.fWusS5+qfCKICtwkfrzcZ/Gq8P0Qdx/kx8mTBhoOhGU'}app.get('/', function (req, res, next) { res.end(JSON.stringify(req.cookies)); console.log(req.session) console.log(req.cookies)});app.listen(3000);cookie-sessio 和express-session 的区别,和适用场合?
1 回答
- 1 回答
- 0 关注
- 1600 浏览
添加回答
举报
0/150
提交
取消