2.0.4 • Published 8 years ago
hapi-server-session-rctech v2.0.4
hapi-server-session
Simple server-side session support for hapi
Install
$ npm install hapi-server-sessionExample
'use strict';
const hapi = require('hapi');
const server = new hapi.Server();
server.connection({
host: 'localhost',
address: '127.0.0.1',
port: 8000,
});
server.register({
register: require('hapi-server-session'),
options: {
cookie: {
isSecure: false,
},
},
}, function (err) { if (err) { throw err; } });
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
request.session.views = request.session.views + 1 || 1;
reply('Views: ' + request.session.views);
},
});
server.start();Options
algorithm: Default:'sha256'algorithm to use during signingcache: supports the same options asserver.cache(options)expiresIn: Default: session idexpiresInif set or2147483647session cache expiration in millisecondssegment: Default:'session'session cache segment
cookie: supports the same options asserver.state(name, [options])isHttpOnly: Default:truesets the HttpOnly flagisSecure: Default:truesets the secure flag. Should never be set tofalsein production
expiresIn: session id expiration in milliseconds. Prevents intercepted cookies from working perpetually. Requireskeyname: Default:'id'name of the cookiekey: signing key. Prevents weaknesses in randomness from affecting overall securitysize: Default:16number of random bytes in the session id
2.0.4
8 years ago