Facility
Facility is a configuration component used to configure Plumier application to get a new ability. It consist some middlewares in a correct order, some process before the application initialized and some default application configuration.
For example to build an API you will need: a Body parser, CORS, Generic error handler and some configuration etc, all can be bundled into one facility called WebApiFacility
.
#
SignatureFacility is a class that implements Facility
, the signature of Facility
is like below:
setup
called during setup process. This method usually used for registering configurations and middlewaresgenerateRoutes
called during initialization process before theinitialize
method. This method provides list of routes produced by Facility.preInitialize
called beforeinitialize
called. This method usually used for some preparation before initialization.initialize
called during initialization process. This method usually used for some preparation required before application run, and possible to call promised functions
#
Develop Your Own FacilityDevelop your own Facility is not required, you can register middleware and set some configuration manually. You develop Facility if you want to make it reusable.
For example the WebApiFacility
facility is like below:
Above code showing that we setup error handler, body parser and cors with some order. Error handler in the top most, it means it will handle all error caused by the next middleware / action.
#
Access Koa from FacilityIn some case if you want to configure Koa, you can do it in facility.