mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Adds Keygrip type to keys in type. * Adds test for keygrip type in cookie-session * Adds small changes to cookie-sessions types. * Reverts formatting because it was bloating the diff. * Adds name to definitions-by section. * Updates TypeScript version in header to allow imports of external types.
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
|
|
|
|
import express = require('express');
|
|
import cookieSession = require('cookie-session');
|
|
import Keygrip = require('keygrip');
|
|
|
|
var app = express()
|
|
|
|
app.set('trust proxy', 1) // trust first proxy
|
|
|
|
app.use(cookieSession({
|
|
name: 'session',
|
|
keys: ['key1', 'key2']
|
|
}))
|
|
|
|
app.use(function (req, res, next) {
|
|
// Update views
|
|
req.session['views'] = (req.session['views'] || 0) + 1
|
|
|
|
// Write response
|
|
res.end(req.session['views'] + ' views')
|
|
})
|
|
|
|
app.listen(3000);
|
|
|
|
|
|
var app2 = express()
|
|
|
|
app2.set('trust proxy', 1) // trust first proxy
|
|
|
|
app2.use(cookieSession({
|
|
name: 'session',
|
|
keys: ['key1', 'key2']
|
|
}))
|
|
|
|
// This allows you to set req.session.maxAge to let certain sessions
|
|
// have a different value than the default.
|
|
app2.use(function (req, res, next) {
|
|
req.sessionOptions.maxAge = req.session['maxAge'] || req.sessionOptions.maxAge
|
|
});
|
|
|
|
|
|
var app3 = express()
|
|
|
|
app3.set('trust proxy', 1) // trust first proxy
|
|
|
|
// a Keygrip object may be used instead of an array of keys.
|
|
app3.use(cookieSession({
|
|
name: 'session',
|
|
keys: Keygrip(['key1', 'key2'])
|
|
})); |