1.0.6 • Published 3 years ago

express-route-handler v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Express Route Manager

Dynamically load route files from the ./routes directory into your Express app.

This package also adds an Error handler for non-existent routes.

Usage

app.js

const router = express.Router();
const Routes = require('./utils/routes');

const routes = new Routes(router, { 
  api: true,
  protection: true
})

app.use(routes.get())

routes/index.js

const controller = require('../controllers/users)

const index = {
  name: "index",
  path: "/api",
  enabled: true,
  routes: [
    {
      name: 'users', 
      method: 'get', 
      fn: controller.users,
      docs: "https://google.com/"
    }
  ]
}

module.exports = index;

Route

KeyDescRequired
nameName of the route, appends to the end of the global path, i.e /api/users.Yes
methodHTTP method.Yes
fnFunction to execute when the endpoint is hit.Yes
middlewareFunction to execute before fn.Yes
docsEndpoint documentation link.No

Options

OptionDescDefault
api: trueToggles /api/routes which returns all routes and link to documentation.false
protection: trueRedirects all requests from urls Array to redirect option.false
urls: ['/.env']Array of URLS to redirect requests away from[./env]
redirect: "/"URL to redirect requests tolink
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago