koa2--07.koa-session的使用
首先安装 koa-session中间件
//koa-session的使用 const koa = require(‘koa‘); var router = require(‘koa-router‘)(); var views = require(‘koa-views‘); const static = require(‘koa-static‘); const bodyParser = require(‘koa-bodyparser‘); var session = require(‘koa-session‘); var app = new koa(); app.use(views(‘views‘,{ map:{ html:‘ejs‘ } })); app.use(bodyParser()); app.use(static(‘./www‘)); //设置签名 var keys = []; ()=>{ for(var i =0;i<1000;i++){ keys.push(Math.random()*100); } }; app.keys = keys; const CONFIG = { keys:‘koa:sess‘, maxAge:1000 }; app.use(session(CONFIG,app));//使用session app.use(router.routes()); app.use(router.allowedMethods()); app.listen(80);
相关推荐
webgm 2020-08-16
Qimingweikun 2019-11-04
oSweetBear 2019-11-04
疯狂紫萧 2020-06-16
lei0 2020-11-02
igogo00 2020-07-04
iconhot 2020-06-26
88481456 2020-06-18
yezitoo 2020-06-06
SelinaChan 2020-05-15
luckymaoyy 2020-04-25
80437700 2020-04-17
austindev 2020-04-07
我有一只小松鼠 2020-02-29
webfullStack 2020-02-15
binglingnew 2012-10-03
始作俑者 2020-01-19
jinxiutong 2020-01-04