Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 1.15 KB

README.md

File metadata and controls

65 lines (53 loc) · 1.15 KB

Express-Router

a npm module for Express app inspired by Nuxt.js

Ability

  • Cli
  • Error handler
  • Auto fetch

Install

npm install express-route-detector

Usage

server.js

const { autoFetch, errorHandler } = require('express-route-detector')
const express = require("express");

const app = express();

app.use(autoFetch(express))
// By defualt pAddress = "hasPermission", cAddress = "controllerw", mAddress = "middleware" 

app.use(autoFetch(
  express,
  pAddress = "hasPermission", //Permission middleware name
  cAddress = "admins", //Controller folder
  mAddress = "middleware" //Middlewawre folder
  ))

app.use(errorHandler);

app.listen(port, () => {
  console.log(`Server runing on port: ${port}`);
});

controller.js

const home = (async (req, res) => {
    res.status(200).json({msg:'Hello world'});
})
module.exports = {
    baseRoute: "/",
    items: [
        {
            off: false,
            route: "/",
            method: "get",
            middleware: [], //option
            permission: "CONTENTUS", //option
            use: home
        },
    ]
}

Cli commends

  • routes
  • monit
  • init
  • env