This is a common controller for using express
Current Status:
$ npm|yarn install express-common-controller
Create a controller inherit BaseController.
- HelloController.js
constBaseController=require('express-common-controller').BaseController;functionHelloController(){}HelloController.prototype=newBaseController();HelloController.prototype.index=function(){this.render("Hello World");};module.exports=HelloController;Or Using ES6 style
import{BaseController}from'express-common-controller';classHelloControllerextendsBaseController{constructor(){super();}index(){this.render('Hello World');}}exportdefaultHelloController;Create a router config like this:
constpath=require('path');constExpressCommonControllerRouter=require('express-common-controller').default;constrouter=newExpressCommonControllerRouter();router.path=path.join(__dirname,'./js/controllers');router.get('/hello','HelloController#hello');module.exports=router.routes();NOTEExpressCommonControllerRouter based on ExpressCommonRouter.
More info please refer to here:express-common-router
Using routes config in server.js
constexpress=require('express');constroutes=require('./routes');constapp=express();app.use(routes);app.listen(3000,'0.0.0.0',(err)=>{if(err){console.log(err);return;}});This component support all methods which supported by express.
About the details of config route, please refer to here: Express Router
express-common-controller is released under the MIT license.
