express-session和cookie-session的区别
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 的区别,和适用场合? |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|