express-json-middleware0.1.0 • Public • Published
A simple minded way to pull in middleware based on a json config file.
This npm is very minimal. Currently its feature list is exactly what I need. If you need other types of routes supports, pull requests / issues are welcome.
Create a routes.json file (or just an in memory array), and pass it in along with the express, express app, and the path to your middlewares directory:
var express =app =createRoutes =routes =path = ;app;app;;app;
Your routes array or routes.json should be an array of arrays. Each line has 3 items.
- The first item is the express
usecommand or an express supported verb.
- use will,
usethe middleware on the app
- a verb will create a new isolated router and use the middlewares listed in the third item
- use will,
- The second item is the routes that this should apply to,
nullif it should be set directly on the default router with no routes.
- The third item is the array of middlewares to be run. Each string will be required in with the middlewares base prefixed to it.
Additionally you can create named stacks of middleware using the "stack" word for the first item, a name for the second item, and a list of middlewares for the thired. These have to be included before being applied. You can include the named stack in your later lists of middlewares and it will be expanded to the full list. This is handy if you have long lists of repeated middlewares.