Closed jhyland87 closed 8 years ago
It should be registrations
, see the example in the usage section:
The issue is that glue v3 recently came out, and it's likely that you're reading a tutorial for v2. The format of the glue manifest has changed between those two versions.
Literally RIGHT when I posted the above, Is came across the same API link you posted above on my own... Thank you.
Is there a good book for V3 you would recommend?
@jhyland87, V3 as been released yesterday, it is pretty unlikely that any book has taken the new format in account yet. However you can just use the v2 for now.
@vdeturckheim, eh, ill use V3, and ill continue to read the book, ill just make sure to look up the documentation for anything I look at.
Thanks!
So I got the basics to work, but it doesn't look like the labels in the registration[ # ].plugin.options.select
are being applied..
'use strict';
import * as Hapi from 'hapi';
import * as Glue from 'glue';
const manifest = {
server: {
//cache: 'redis'
},
connections: [
{
port: 8000,
labels: ['api']
},
{
port: 8001,
labels: ['http']
}
],
registrations: [
{
plugin: {
register: './routes',
options: {
select: [ 'api' ]
}
}
}
]
};
const options = {
relativeTo: __dirname
};
Glue.compose(manifest, options, (err, server) => {
if (err) throw err;
server.start(() => {
console.log('hapi days!');
});
});
Then the routes.js is:
// routes.js
'use strict';
exports.register = (server, options, next) => {
server.route({
method: 'GET',
path: '/hello-world',
handler: (request, reply) => {
reply( 'test passed' );
}
});
next();
};
exports.register.attributes = {
pkg: {
name: "helloWorld",
version: "0.1.0"
}
};
However the /hello-world
works for both ports, am I doing something wrong? (im sure)
The code in glue doesn't look good to me. Created a PR to fix this.
Oh ok, I thought I was going crazy.
Thanks!
You want to pass that as a registration option, not a plugin init option. ie.
registrations: [
{
plugin: {
register: './routes',
},
options: {
select: [ 'api' ]
}
}
]
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
I'm reading the Developing a Hapi Edge book, and wanted to try to get a basic HapiJS API server going using Glue, the JS is pretty much right from the book, and even took some of the plugins out, but it looks like it should work: http://pastebin.com/x6Wftvhd (Transpiled ES5 version: http://pastebin.com/PH9qiFut)
However, it returns an error in the console:
Any ideas?