koa-cookie
/
1.4.11
koa-cookie 1.4.11
Install from the command line:
Learn more about npm packages
$ npm install @uswitch/koa-cookie@1.4.11
Install via package.json:
"@uswitch/koa-cookie": "1.4.11"
About this version
Cookie parser middleware for koa. Can also be used with koa-router.
npm install @uswitch/koa-cookie --save
import Koa from 'koa';
import cookie from '@uswitch/koa-cookie';
const app = Koa();
app.use(cookie());
app.use(async function (ctx, next) {
const cookies = ctx.cookie;
/*
if cookies sent are of the form: 'name=abc; age=20; token = xyz;'
Then ctx.cookie is an object of the form:
{
name: 'abc',
age: '20',
token: 'xyz'
}
*/
});
var app = require('koa')();
var cookie = require('@uswitch/koa-cookie');
var router = require('koa-router')();
router.use(cookie.default());
router.get('/', async (context) => {
const cookies = context.cookie;
/*
if cookies sent are of the form: 'name=abc; age=20; token = xyz;'
Then ctx.cookie is an object of the form:
{
name: 'abc',
age: '20',
token: 'xyz'
}
*/
});
app
.use(router.routes())
.use(router.allowedMethods());