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.
Signature#
Facility is a class that implements Facility, the signature of Facility is like below:
setupcalled during setup process. This method usually used for registering configurations and middlewaresgenerateRoutescalled during initialization process before theinitializemethod. This method provides list of routes produced by Facility.preInitializecalled beforeinitializecalled. This method usually used for some preparation before initialization.initializecalled during initialization process. This method usually used for some preparation required before application run, and possible to call promised functions
Develop Your Own Facility#
Develop 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 Facility#
In some case if you want to configure Koa, you can do it in facility.
