示例
const Koa = require('koa'),
router = require('koa-router')();
const app = new Koa();
router
.get('/', async ctx => {
let data = ctx.cookies.get('name');
ctx.body = `<h1>${data}</h1>`;
})
.get('/login', async ctx => {
ctx.cookies.set('name', 'ProsperLee', { maxAge: 3000 });
ctx.body = '<a href="/">index</a>';
})
app
.use(router.routes())
.use(router.allowedMethods())
.listen(3000);
console.log('Server run in http://localhost:3000/');
结果