Definitiondynamic class Route
InheritanceRoute inherit Object

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.


limitsObjectResource limits for the request. See HttpServer.limits for details.
locationObjectApplication 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.
methodStringHTTP method to match. If set to "" or "*"", all methods are matched.
middlewareArrayMiddleware to run on requests for this route. Middleware wraps the application function filtering and modifying its inputs and outputs.
moduleNameStringName of a required module containing code to serve requests on this route.
nameStringRoute name. This is local to the route set (controller).
paramsObjectRequest parameters to add to the Request.params. This optional override hash provides parameters which will be defined in Request.params[].
redirectStringURI to redirect the request toward.
responseObjectResponse object hash or function to serve the request.
rewriteFunctionRewrite 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.
routeSetNameStringRoute set owning the route. This is the first component of the template.
targetStringTarget mapping for the route. The route maps from the template to the target.
templateObjectTemplate 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.
routerRouterRouter instance reference.
tokensArrayKey tokens in the route template.
traceObjectTrace 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.
workersBooleanIf 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

(No own class methods defined)


Route Instance Methods

Route(template: Object, options: Object, router: Router)
 Create a new Route instance.

Method Detail

ejs.web Route(template: Object, options: Object, router: Router)
Create a new Route instance. This is normally not invoked directly. Rather Router.add() is used to create and install routes into the Router.
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.
actionAction 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.
controllerController to service the request.
methodHTTP Method for which the route is valid. Set to "*"" for all methods.
nameName to give to the route. If absent, the name is created from the controller and action names.
outerParent route. The parent's template and parameters are appended to this route.
paramsOverride parameter to provide to the request in the Request.params.
Route("/{controller}(/{action}(/{id}))/", { method: "POST" })
Route("/User/login", {name: "login" })