1.0.0-alpha.1.7 • Published 6 years ago

@midgar/route-loader v1.0.0-alpha.1.7

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

In Dev don't use this

@midgar/route-loader

It a plugin for Midgar to load routes

Installation

$ npm install @midgar/route-loader --save

Plugin dir

This plugin add a routes plugin dir. It load all router in this directories.

Router file

const Router = require('@midgar/route-loader/libs/router')

class MyRouter extends Router {

  /**
   * return routes définitions
   */
  async getRoutes() {
    return [
      {
        method: 'post',
        path: '/login',
        action: '_login'
      },
      {
        path: '/customer',
        action: '_customer'
      }
    ]
  }

  _login(req, res) {
    let response = {
        success: true
    }
    res.json(response)
  }

  _customer(req, res) {
    const response = {
      name: 'foo'
    }

    res.json(response);
  }
}

module.exports = MyRouter