Socket
Socket
Sign inDemoInstall

app-router

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    app-router

Routing for expressjs


Version published
Weekly downloads
6
increased by20%
Maintainers
1
Install size
8.60 kB
Created
Weekly downloads
 

Readme

Source

app-router

routing for expressjs

usage
var express= require("express");
var app = express();
var router = require("app-router");
router(app).setCWD(__dirname).route("./routes/route.json");

setting current working directory (CWD) relative to all controllers path and route.json

setCWD(__dirname)

sample route.json

{
    "GLOBAL":{
        "cp":"./controllers/my_controller",
        "other_controller":"./controllers/other_controller.js"
	},
	"GET":{
		"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"],
		"/user/:id" : "{cp}:myClass.myMethod"
	},
	"POST":{
		"/hello" : "./controllers/my_controller:createApp"
	},
	"PUT":{
		"/hello" : "{other_controller}:helloPut"
	},
	"DELETE":{
		"/user" : "./controllers/other_controller.js:destroyApp"
	},
	"RESOURCE":{
		"/res" 	: "{cp}",
		"/user"	: "./controllers/user_controller.js"
	}
}

Resource action mapping

Actions are mapped accordingly:


"RESOURCE":{
	"/user" : "./controllers/user_controller.js"
}

Method  Route                           Action (in controller ./controllers/user_controller.js)
GET     /user               		->  index
GET     /user.:format               ->  index
GET     /user/new                   ->  new
GET     /user/new.:format           ->  new
POST    /user                       ->  create
POST    /user.:format           	->  create
GET     /user/:id           		->  show
GET     /user/:id.:format       	->  show
GET     /user/:id/edit              ->  edit
GET     /user/:id/edit.:format      ->  edit
PUT     /user/:id                   ->  update
PUT     /user/:id.:format           ->  update
DELETE  /user/:id                   ->  destroy
DELETE  /user/:id.:format           ->  destroy

Basic syntax for route.json

{"/app_route" : [ "path_to_controller:method_name" ]}

OR

{"/app_route" : [ "path_to_controller:class_name.method_name" ]}

OR

{"/app_route" : [
	"path_to_controller:middleware_one", 
	"path_to_controller:middleware_two", 
	"path_to_controller:method_name" 
	]
}

Keywords

FAQs

Last updated on 02 Feb 2014

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc