Skip to content

admatic-tool/express-routes-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExpressRoutesHelper

get started

make a config file

module.exports = {
  host: "//www.yourdomain.com",
  debug: true,
  routes: [
    { from: "GET /page/:slug/:id", to: "pages#show" },
    { method: "GET",
      path: "/",
      controller: "PagesController",
      action: "welcome"
    }
  ]
}

route parameters

use to key to specify a pair controller#method.

use from to specify a pair http verb (or any express route method) and path

/* Example
* this will set get path with pattern ""/page/:slug/:id"
* use module exported in controllers/pages-controller.js
* in method show(req, res)
*/
{ from: "GET /page/:slug/:id", to: "pages#show" },

use as key to overwrite a function name

{ from: "GET /page/:slug/:id", to: "pages#show", as: "myCustomName" },

it will generate a method myCustomNameUrl({url , id}) instead pagesShowUrl({url , id})

init in express

const ExpressRoutesHelper = require("express-routes-helper")

let expressRoutesHelper = new ExpressRoutesHelper(app)
expressRoutesHelper.build(config)

ChangeLogs

  • 2016-10-02 added support to as parameter in config route name function

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published