<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ``` ~~~ /** * koa 中 session 的使用 * 1、npm install koa-session --save * 2、const session = require('koa-session'); * 3、app.keys = ['some secret hurr']; * const CONFIG = { * key: 'koa:sess', * maxAge: 86400000, * overwrite: true, * httpOnly: true, * signed: true, * rolling: false, * renew: false * } * * 4、設置 session * ctx.session.username = '張三'; * 5、獲取 session * ctx.session.username */ // 引入模塊 const Koa = require('koa'); const router = require('koa-router')(); /*引入是實例化路由 推薦*/ const render = require('koa-art-template'); const path = require('path'); const session = require('koa-session'); // 實例化 let app = new Koa(); // 配置 koa-art-template 模板引擎 render(app, { root: path.join(__dirname, 'views'), // 視圖的位置 extname: '.html', // 后綴名 debug: process.env.NODE_ENV !== 'production' // 是否開啟調試模式 }); // 配置session的中間件 app.keys = ['some secret hurr']; /** cookie的簽名 */ const CONFIG = { key: 'koa:sess', /** 默認 */ maxAge: 86400000, /** cookie的過期時間 【需要修改】*/ overwrite: true, /** (boolean) can overwrite or not (default true) 沒有效果 默認*/ httpOnly: true, /** true表示只有服務器端可以獲取cookie*/ signed: true, /** 默認 簽名 */ rolling: false, /** 在每次請求時強行設置 cookie,這將重置 cookie 過期時間(默認:false) 【需要修改】*/ renew: true, /** (boolean) renew session when session is nearly expired 【需要修改】*/ }; app.use(session(CONFIG, app)); router.get('/', async (ctx) => { // 獲取session console.log(ctx.session.userinfo); await ctx.render('index', { list: { name: '張三' } }); }) router.get('/news', async (ctx) => { // 獲取session console.log(ctx.session.userinfo); ctx.body = '新聞頁面'; }) router.get('/login', async (ctx) => { // 設置session ctx.session.userinfo = '張三'; ctx.body = '登錄成功'; }) app.use(router.routes()); app.use(router.allowedMethods()); app.listen(8000); ~~~ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看