Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

v0.1.2 assignment2 Plugins #262

Closed
zoe-1 opened this issue Jun 24, 2018 · 0 comments
Closed

v0.1.2 assignment2 Plugins #262

zoe-1 opened this issue Jun 24, 2018 · 0 comments
Milestone

Comments

@zoe-1
Copy link
Contributor

zoe-1 commented Jun 24, 2018

[Assignment2] Plugins

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 plugin register() 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 in the comments of the
issue created for the assignment. If you are not sure how to get your fork back in sync with the current updated code, use the
git guide.

Helps

  • require('./version') should be declared at the top and assigned to Version`.
  • no need to wrap the plugin in { register: Version }. It is enough to just pass Version directly to the register() function.
  • no need for specifying the plugin version in the attributes. This is an internal plugin, not a publicly published one.

source for Helps: Discussion between @hueniverse and @thealphanerd.
Original Assignment2

Assignment2 Solution

@zoe-1 zoe-1 changed the title v0.1.2 assignment2 v0.1.2 assignment2 Plugins Jun 24, 2018
@zoe-1 zoe-1 added this to the v0.1.2 milestone Jun 24, 2018
@zoe-1 zoe-1 removed the assignment label Jun 24, 2018
@zoe-1 zoe-1 closed this as completed Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant