cookie-based session:
Write all information on the cookie. Server don't need to store information.When client want to ask information from server. Client take cookie to server, server understand all information from cookie.And server send back data to client.
--- blog-system/app.js 2017-03-15 02:04:02.049999999 +0000
+++ blog-system/app.js 2017-03-15 02:00:47.430000007 +0000
@@ -4,6 +4,7 @@
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
+var cookieSession = require('cookie-session')
var index = require('./routes/index');
var users = require('./routes/users');
@@ -22,6 +23,12 @@
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
+
+app.use(cookieSession({
+ key: 'node',
+ secret: 'HelloExpressSESSION'
+}))
+
app.use('/', index);
app.use('/users', users);
If modify "package.json", please type "npm install" to install dependencies.
--- test/blog-system/package.json 2017-03-15 02:04:02.049999999 +0000
+++ blog-system/package.json 2017-03-15 02:01:56.426666659 +0000
@@ -12,6 +12,8 @@
"express": "~4.14.1",
"jade": "~1.11.0",
"morgan": "~1.7.0",
- "serve-favicon": "~2.3.2"
+ "serve-favicon": "~2.3.2",
+ "cookie-session": "*",
+ "mongoose": "*"
}
}
0 意見:
張貼留言