New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mini-route-loader

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-route-loader

Load routes to controllers for Express

latest
npmnpm
Version
0.25.1
Version published
Maintainers
1
Created
Source

Mini Route Loader

Route file configuration for express

See the unit test for implementation instructions

In your express initialization code

    import MiniRouteLoader from 'mini-route-loader'

    import APIController from '../controllers/APIController'

    const Routes = JSON.parse( fs.readFileSync('./server/routes/routes.json') )

    this.apiController=new APIController(  )
            



    const app = express()

    MiniRouteLoader.loadRoutes( app, Routes , this.apiController  )

    app.listen(apiPort, () => {
    console.log(`API Server listening at http://localhost:${apiPort}`)
    })

Anatomy of a route

Each route must have the following:

Type: A string, either 'get' or 'post' for the type of REST request to expect

uri: The uri onto which to expose the route with express

method: The name of the controller method to call (the method must extend APICall

Each route may additionally specify the following optional attributes:

controller: The name of the controller that has the methods for this route

appendParams: An object that will be appended to 'req' just before it is passed to the method in the controller. This will be appended at 'req.router.params'

In routes.json

[ {"type":"get","uri":"/api/ping","method":"ping","controller":"api"}

]

In your controller class

    import { APICall } from "mini-route-loader"


    export default class APIController  {

        ping: APICall =  async (req: any, res: any) => {
            return res.status(200).send('Pong')
        }

    }

FAQs

Package last updated on 06 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts