@cork-labs/http-middleware-cookies
v0.3.1
Published
Express middleware, exposes simple cookie related methods in res
Downloads
18
Readme
HTTP Middleware Cookies
Express middleware, exposes simple cookie related methods in
res
.
Getting Started
npm install --save @cork-labs/http-middleware-cookies
// your application setup
const httpCookies = require('@cork-labs/http-middleware-cookies');
app.use(httpCookies());
// your route
app.get('/path', (req, res, next) => {
res.setCookie('name', 'value');
})
API
res.setCookie(name, value[, maxAge])
Sets a cookie valid for the provided maxAge
(in seconds).
If no maxAge
provided will use the one provided at configuration time.
res.setSessionCookie(name, value)
Sets a cookie valid for the session only.
Configuration
The middleware can be configured via an options object when calling its factory function.
const options = { domain: 'example.com', maxAge: 24 * 60 * 60 };
app.use(httpCookies(options));
secure (default: true)
All cookies are flagged as secure, meaning the browser will only return them when connecting over encrypted connections.
It's only safe to switch this setting to false
in development environments.
domain (default: null)
All cookies set are valid for this domain.
maxAge (default: null)
Default time to live (in seconds) for cookies set with setCookie()
.
If no default is configured, setCookie()
will act as setSessionCookie()
Develop
# lint and fix
npm run lint
# run test suite
npm test
# lint and test
npm run build
# serve test coverage
npm run coverage
# publish a minor version
node_modules/.bin/npm-bump minor
Contributing
We'd love for you to contribute to our source code and to make it even better than it is today!
Check CONTRIBUTING before submitting issues and PRs.