-
Notifications
You must be signed in to change notification settings - Fork 194
Convert to a plugin #43
Comments
Nice git guide! |
How far do we need to go with the plugin? e.g. add its own package.json and tests? |
I was under the impression that since we were asked to make I was also noticing the amount of noise that my pr has created referencing this issue... is this a problem? |
yeah I guess and I noticed the noise to. How come? Looks like the same commit every time? |
OHHHHHH I think it is from my rebasing |
aaah probably yes |
Btw
FTW!!! |
for adding to an existing commit? |
mmhmmm. That alias will take all staged chages and squash them down into the last commit. |
No need for a standalone plugin module, just the one file. |
👍 |
I have now this. index.js :
version.js
but still I see this error message : Error: Cannot find module 'version' Roelof |
@roelof1967 you should do |
Thanks, I had to change require (version) to require(./version) and the error message disappear. |
Quick questions:
server.register({ register: plugin }, function (err) {
server.start(function (err) { /*...*/ })
}) vs server.register({ register: plugin }, function (err) {
/*...*/
});
server.start(function (err) { /*...*/ }); |
|
|
@Couto as far as I'm concerned the later is just plain wrong :P |
Should server.register({ register: Version }, function (err) {
Hoek.assert(!err, err);
server.start(function (err) {
Hoek.assert(!err, err);
console.log('Server started at: ' + server.info.uri);
});
}); server.register({ register: Version }, function (err) {
Hoek.assert(!err, err);
});
server.start(function (err) {
Hoek.assert(!err, err);
console.log('Server started at: ' + server.info.uri);
}); Both seems to work (also the second option when switching the |
Better to start the server in the register callback so you are sure all the plugins are loaded correctly before starting |
General feedback:
|
@hueniverse is there a preferred pattern for handling async when you are registering multiple plugins? |
You can pass an array if they all share the same (or lack of) options. Otherwise, you can use the glue module or create your own utility. |
The right way to work with hapi is to build your application using plugins. Plugins provide a way to organize your code into logical components and then put them together in different combinations or deploy them in different configurations. While some plugins are published as general purpose utilities (e.g. adding authentication), you should think of plugins as a way to break your code into pieces.
Now that we have a basic server with one endpoint, we want to move the creation of the endpoint to a plugin, and then register that plugin with the server. Creating a new file
lib/version.js
and move the/version
endpoint there, wrapped in the pluginregister()
function.Then change our current
lib/index.js
to require the new file and register the version plugin with our server.Remember to follow the style guide, and ask any questions right here in the comments. If you are not sure how to get your fork back in sync with the current updated code, use the git guide.
Assignment due: 3/24
The text was updated successfully, but these errors were encountered: