Express Common Router
This is a common router for express.
Current Status:
Installation
$ npm|yarn install express-common-router
Usage
First step:
Create two handlers:
- Hello.js
module { res;};
- Test.js
exports { res;};exports { res;}
- NotFound.js
exports { res;};
Second step:
Create a routes config.
- routes.js
const path = ;const ExpressCommonRouter = default; const handlerPath = pathconst router = handlerPath; router; //Must use the same name with file name.router; //Handler name and action name separated by '#'router; //More method please refer to 'express'routerall'*' 'NotFound'; //More method please refer to 'express' moduleexports = router;
ES6 Style
;; const router = ;routerpath = path; router; //Must use the same name with file name.router; //Handler name and action name separated by '#'router; //More method please refer to 'express' moduleexports = router;
Third step:
Using routes in server.js
const express = ;const routes = ;const app = ; app; app;
More Details
How to set handler file path?
- Passing
path
as a parameter when create an instance of ExpressCommonRouter.
const handlerPath = path;const router = handlerPath;
- Calling
path
method for ExpressCommonRouter instance.
const router = ;routerpath = path;
Set custom HandlerManager.
- Create a custom HandlerManager like this:
{ ... };
- Config CustomHandlerManager into router config file.
;; const router = ;routermanageractionManager = ;
Set custom FileLoader.
- Create a custom FileLoader like this:
{ ... };
- Config CustomFileLoader into router config file.
;; const router = ;routermanagerfileLoader = ;
Set custom HandlerLoader.
- Create a custom HandlerLoader like this:
{ ... };
- Config CustomHandlerLoader into router config file.
;; const router = ;routermanagerhandlerLoader = ;
Set custom ActionLoader.
- Create a custom ActionLoader like this:
{ ... };
- Config CustomActionLoader into router config file.
;; const router = ;routermanageractionLoader = ;
Config your routes.
This component support all methods which supported by express
.
About the details of config route, please refer to here: Express Router
License
express-common-router is released under the MIT license.