Class: HTTPRoute

server.HTTPRoute

Class representing a HTTP route.

Routes may be used to implement virtual servers, or just for handling different URLs with different backends.

The function of the when property decides if a request is to be handled by a HTTP route.

Example

Implement virtual servers by evaluating the HTTP Host header.

HTTPRoute {
    when: req => req.headers.get("Host") === "virtualhost1.com"
}

The delegate property holds a server.HTTPSession element as a template from which sessions handlers are created dynamically. A session is identified by the result of the generateSessionId function, and the same session will reuse the same session handler for further requests.

Example

Identify sessions by cookie.

HTTPRoute {
    generateSessionId: req => req.cookies.get("Session-Cookie") || ""
}

If the authentication property is set to an authentication method, only authenticated requests will be accepted.

new server.HTTPRoute ()

Properties:
Name Type Description
authentication server.HTTPAuth

(default: null) The authentication method, or null.

delegate server.HTTPSession

(default: null) The session delegate.

generateSessionId function

A function for generating a session ID out of a request.

when function

(default: request => true) A function for testing whether a request is to be handled by a request.

Extends

Methods

Returns the server.HTTPSession for the given ID. Creates a new session, if necessary.

Name Type Description
id string

The session ID.

Returns:
Type Description
server.HTTPSession The session.

pathPrefix (p)function

Creates a simple predicate for when that tests just for a path prefix.

Name Type Description
p string

The path prefix to test for.

Returns:
Type Description
function A predicate function to use for when.