1.发送cookie
const express = requier('express');
var server = express();
server.use('aaa/a.html',function(req,res){
res.cookie('user','jack',{path:'/aaa',Maxage:30*24*60*60*100})//Maxage存储的时间长短
})
server.listen(8080);
读取cookie
//需要下载cookie-parser中间件
const express = require('express');
const cookieParser = require('cookie-parser');
var server = express();
server.use(cookieParser());
server.use('/aaa/a.html',function(req,res){
console.log(req.cookie);
res.send('ok');
})
server.listen(8080);
加密cookie
const express = require('express');
const cookieParser = require('cookie-parser');
var server = express();
server.use(cookieParser());
server.use('/',function(req,res){
//声明密钥
req.secret='ewsdpfpew';
res.cookie('uname','lucky',{signed:true})//设置签名
res.send('ok')
})
server.listen(8080)
网友评论