Route
Module | ejs.web |
Definition | dynamic class Route |
Inheritance | Route ![]() |
A Route describes a mapping from a URI to a web application.
A route has a URI template for matching with
candidate request URIs and a serving function to respond to the request.
If the URI template is a regular expression, it is used to match against the request pathInfo. If it matches,
the pathInfo is matched and sub-expressions may be referenced in the override parameters by using 1 2 and
so on. e.g. { priority: "1" }
If the URL template is a function, it is run to test for a request match. It should return true to
accept the request. The function can set parameters in request.params.
The optional override params hash provides parameters which will be defined in params[] overriding any tokenized
parameters previously set.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
limits | Object | Resource limits for the request. See HttpServer.limits for details. | |
location | Object | Application location to serve the request. Location contains two properties: scriptName which is the string URI prefix for the application and dir which is a Path to the physical file system directory containing the applciation. | |
method | String | HTTP method to match. If set to "" or "*"", all methods are matched. | |
middleware | Array | Middleware to run on requests for this route. Middleware wraps the application function filtering and modifying its inputs and outputs. | |
moduleName | String | Name of a required module containing code to serve requests on this route. | |
name | String | Route name. This is local to the route set (controller). | |
params | Object | Request parameters to add to the Request.params. This optional override hash provides parameters which will be defined in Request.params[]. | |
redirect | String | URI to redirect the request toward. | |
response | Object | Response object hash or function to serve the request. | |
rewrite | Function | Rewrite function to rewrite the request before serving. It may update the request scriptName, pathInfo and other Request properties. Return true to continue serving the request on this route. Otherwise re-route after rewriting the request. | |
routeSetName | String | Route set owning the route. This is the first component of the template. | |
target | String | Target mapping for the route. The route maps from the template to the target. | |
template | Object | Template pattern for creating links. The template is used to match the request pathInfo. The template can be a
string, a regular expression or a function. If it is a string, it may contain tokens enclosed in braces
"{}" and it is converted to a regular expression for fast matching. At run-time, request tokens
are extracted and stored as items in the Request.params collection. If the template is a regular expression, it is used to match against the request pathInfo. If it matches, then sub-expressions may be referenced in the params values by using 1 2 and so on. e.g. params: { priority: "1" } If the template is a function, it is run to test for a request match. The function should return true to match the request. The function can directly set parameters in request.params. | |
router | Router | Router instance reference. | |
tokens | Array | Key tokens in the route template. | |
trace | Object | Trace options for the request. Note: the route is created after the Request object is created so the tracing of the connections and request headers will be controlled by the owning server. See HttpServer.trace for trace property fields. | |
workers | Boolean | If true, requests should execute using a worker thread if possible. The worker thread will be pooled when the request completes and be available for use by subsequent requests. |
Route Class Methods
Qualifiers | Method |
---|
Route Instance Methods
Qualifiers | Method |
---|---|
Route(template: Object, options: Object, router: Router) | |
Create a new Route instance. |
Method Detail
- Description
- Create a new Route instance. This is normally not invoked directly. Rather Router.add() is used to create and install routes into the Router.
- Parameters
template: Object String or Regular Expression defining the form of a matching URI (Request.pathInfo). options: Object Route options representing the URI and options to use when servicing the request. If it is a string, it may begin with an " @" and be of the form " @[controller/]action". In this case, if there is a "/" delimiter, the first portion is a controller and the second is the controller action to invoke. The controller or action may be absent. For example: " @Controller/", " @action", " @controller/action". If the string does not begin with an " @", it is interpreted as a literal URI. For example: "/web/index.html". If the options is an object hash, it may contain the options below:. router: Router Owning router object.
- Options
action Action method to service the request. This may be of the form "action", "controller/action" or "controller/". If the action portion omitted, the default action (index) will be used. controller Controller to service the request. method HTTP Method for which the route is valid. Set to "*"" for all methods. name Name to give to the route. If absent, the name is created from the controller and action names. outer Parent route. The parent's template and parameters are appended to this route. params Override parameter to provide to the request in the Request.params.
- Example
Route("/{controller}(/{action}(/{id}))/", { method: "POST" }) Route("/User/login", {name: "login" })