
Use class methods to add lifecycle extension points to your hapi server.
Installation · Usage · Contribute
Follow @marcuspoehls for updates!
The Future Studio University supports development of this hapi plugin 🚀
Join the Future Studio University and Skyrocket in Node.js
Introduction
This hapi plugin adds the server.extClass(class)
decoration to register lifecycle extensions from class methods.
Requirements
hapi v19 (or later) and Node.js v12 (or newer)
This plugin requires hapi v19 (or later) and Node.js v12 or newer.
Compatibility
Major Release | hapi.js version | Node.js version |
---|---|---|
v2 |
>=17 hapi |
>=12 |
v1 |
>=17 hapi |
>=8 |
Installation
Add hapi-class-extension-points
as a dependency to your project:
npm i hapi-class-extension-points
Usage
Register hapi-class-extension-points
to your hapi server. This will decorate the hapi server
with a server.extClass()
method:
await server // went smooth like chocolate :)// now your hapi server supports 'server.extClass(class MyMiddleware {})'
Having the plugin registered, you can now write your lifecycle extension points as classes:
{ thisserver = server } async { // rate limit the request await this return hcontinue } async { // this is a private method that won't be registered as a lifecycle extension } { // add rate limiting headers return hcontinue } server
That's it! The constructor of your class receives the hapi server. You can then store it as a class property and use it when needed!
Enjoy!
Links & Resources
- hapi tutorial series with 100+ tutorials
Contributing
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
License
MIT © Future Studio
futurestud.io · GitHub @futurestudio · Twitter @futurestud_io