Skip to content

Instantly share code, notes, and snippets.

@PaulMougel
Created May 6, 2014 12:18
Show Gist options
  • Save PaulMougel/2f33c5642b46034f1298 to your computer and use it in GitHub Desktop.
Save PaulMougel/2f33c5642b46034f1298 to your computer and use it in GitHub Desktop.
Hapi hanging with plugin dependency
var Hapi = require('hapi');
var plugins = {
yar: {
cookieOptions: {
password: "mypassword",
isSecure: false
}
},
travelogue: {
hostname: "localhost",
port: 8082,
urls: {
failureRedirect: "/auth/login.html",
successRedirect: "/auth/login"
}
},
'./test-plugin': {}
};
var server = new Hapi.Server('localhost', 8082);
server.pack.require(plugins, function(err) {
if (err) throw err;
server.start();
});
{
"name": "hapiTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"yar": "~2.1.0",
"travelogue": "~2.0.0",
"hapi": "~3.1.0",
"passport": "~0.2.0",
"passport-persona": "~0.1.7"
}
}
// The file is stored in test-plugin/index.js
// for some reason gists don't allow / in file names...
exports.register = function (plugin, options, next) {
// Crashes at startup:
// undefined.someProperty;
plugin.dependency('travelogue', after);
next();
};
function after (plugin, next) {
// Hangs but doesn't crash:
// undefined.someProperty;
plugin.route({
path: '/',
method: 'GET',
handler: function (request, reply) {
reply({ok: true})
}
})
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment