Skip to content

Instantly share code, notes, and snippets.

@cadecairos
Last active August 29, 2015 14:18
Show Gist options
  • Save cadecairos/5bcfa6aeba06c2c69952 to your computer and use it in GitHub Desktop.
Save cadecairos/5bcfa6aeba06c2c69952 to your computer and use it in GitHub Desktop.
var Hapi = require('hapi');
var Hoek = require('hoek');
var Path = require('path');
var server = new Hapi.Server();
server.connection({
host: "localhost",
port: 7878
});
server.register(require('hapi-auth-cookie'), function(err) {
server.auth.strategy('session', 'cookie', {
password: "sekret",
cookie: 'wat',
ttl: 1000 * 60 * 60 * 24,
isSecure: false,
isHttpOnly: true
});
server.auth.default({
strategy: 'session',
mode: 'try'
});
});
server.route([
{
method: 'GET',
path: '/',
handler: {
file: {
path: Path.join(__dirname, './cookie.html')
}
}
},
{
method: 'POST',
path: '/',
handler: function(request, reply) {
request.auth.session.set({
"wat": "wat"
});
reply({ status: 'Logged In' });
}
}
]);
server.start(function(error) {
Hoek.assert(!error, error);
console.log('Server running at: %s', server.info.uri);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment