Simple router class for directing requests
new (require("skyring/lib/server/router"))(node, timer)
Parameters:
| Name | Type | Description |
|---|---|---|
node |
module:skyring/lib/server/node | The node linked to the application hashring to pass with each request |
timer |
module:skyring/lib/timer | A timer instance associated with the application hashring to pass with each request |
- Source:
Example
var x = new Router(node, timers) router.handle(req, res)
Requires
- module:skyring/lib/server/route
- module:skyring/lib/server/request
- module:skyring/lib/server/response
Methods
-
delete(path, handler)
-
Adds a new delete handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
get(path, handler)
-
Adds a new get handler to the router a new get handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
handle(req, res)
-
Entrypoint for an incoming request Customer properties are attached to an
$object on the request rather than the request itself to avoid V8 deopts / perf penaltiesParameters:
Name Type Description reqhttp.IncomingMessage reshttp.ServerResponse - Source:
Example
http.createServer((req, res) => { router.handle(req, res) }) -
handleRoute(route, req, res)
-
Responsible for executing the middleware stack on the route ( including the end handler )
Parameters:
Name Type Description routemodule:skyring/lib/server/route reqhttp.IncomingMessage reshttp.ServerResponse - Source:
-
options(path, handler)
-
Adds a new opts handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
patch(path, handler)
-
Adds a new patch handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
post(path, handler)
-
Adds a new post handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
put(path, handler)
-
Adds a new put handler to the router
Parameters:
Name Type Description pathString The url path to route on
handlerfunction The handler function to call when the route is matched
- Source:
-
route(path, m, The)
-
Adds a new route handler to the router
Parameters:
Name Type Description pathString The url path to route on
mString handlerethod The http method to associate to the route
Thefunction handler function to call when the route is matched
- Source:
Returns: