Load Route Files
A package to load all route files to then use them as middlewares. I built and tested with Koa, but as agnostic it is, probably can be implemented in any other framework.
Instalation
Just run:
npm i load-route-files
Usage
In your project, you should have a folder with subfolders. Those folders should contain a routes.js
file inside.
In this example I use a folder called domains
. So the structure should be at least the following:
.
├── ...
├── api.js
├── domains
│ ├── users
│ │ ├── routes.js
| | └── ...
│ └── permissions
| ├── routes.js
| └── ...
└── ...
// in api.js const Koa = ; const api = ; const loadRoutes = ; const routes = await ; const koaCompose = ; //takes an array of milewares and compose them as one. api;
You can also specify a routeFilename
in config, with is a custom name for the route file, if you wish.