Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zacanger/koa-cookies
Set, clear, and parse cookies in your Koa application
https://github.com/zacanger/koa-cookies
cookie cookies koa set-cookie
Last synced: 2 months ago
JSON representation
Set, clear, and parse cookies in your Koa application
- Host: GitHub
- URL: https://github.com/zacanger/koa-cookies
- Owner: zacanger
- License: mit
- Created: 2018-09-16T02:31:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T06:21:51.000Z (7 months ago)
- Last Synced: 2024-11-01T06:51:38.329Z (3 months ago)
- Topics: cookie, cookies, koa, set-cookie
- Language: TypeScript
- Homepage: http://npm.im/koa-cookies
- Size: 1.26 MB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# koa-cookies
Set, clear, and parse cookies in your Koa application.
[Donate](https://ko-fi.com/zacanger)
--------
## Installation
`npm i koa-cookies`
## Usage
```javascript
// set up your koa server, koa-router, etc.
import { clearCookie, setCookie, parseCookie } from 'koa-cookies'// Use in routes
app.get('/foo', async (ctx, next) => {
await setCookie('bar', 'baz')(ctx) // => void
})
app.get('/things', async (ctx) => {
await clearCookie('foo')(ctx) // => void
})
app.get('/stuff', async (ctx) => {
await parseCookie('bar')(ctx) // => string value for this cookie key
})// Use as middlewares
app.use(setCookie('foo', 'bar', config)) // set on every request
app.use(clearCookie('baz', config)) // clear on every request
app.use(parseCookie()) // always add all cookies to ctx.cookies
```The `config` argument is optional. Defaults:
```
setCookieConfig = {
domain: ctx.host,
maxAge: one week,
expires: one week from now
}clearCookieConfig = {
domain: ctx.host,
maxAge: 1 second,
expires: 1970-01-01T00:00:00.001Z
}
```[LICENSE](./LICENSE.md)