Class: HTTPServer

server.HTTPServer

Class representing a HTTP or HTTPS server.

The HTTP server passes requests to its server.HTTPRoute child elements. The HTTP route handling the request will create or re-use a delegate server.HTTPSession handler.

Every request is handled by at most one HTTP route.

Example

HTTPServer {
    port: 8080

    HTTPRoute {
        // handle requests with path starting with "/api"
        when: req => req.url.path.startsWith("/api")

        delegate: template HTTPSession {

        }
    }

    HTTPRoute {
        // handle all remaining requests

        delegate: template WebSession {

        }
    }
}

new server.HTTPServer ()

Properties:
Name Type Description
certificate string

(default: "") The path to the server certificate in PEM format, if secure is set.

enabled bool

(default: true) Whether the HTTP server is enabled or disabled.

host string

(default: "0.0.0.0") The host address to listen at.

keepAlive number

(default: 5000) The time in ms to keep a client connection alive, if the client requested so.

key string

(default: "") The path to the server private key in PEM format, if secure is set.

port number

(default: 8000) The port number to listen at.

secure bool

(default: false) If true, the server uses SSL and requires the certificate and key properties to be set.

Extends

Type Definitions

server.HTTPServer.HTTPRequestEvent

A HTTP request event.

Properties:
Name Type Description
accepted bool

(default: false) Set to true to accept the event and prevent it from bubbling up.

cookies Map

A map of the HTTP cookies.

headers Map

A map of the HTTP headers.

method string

The name of the HTTP method.

original HTTPRequest

The original HTTP request of Node.js.

sourceAddress string

The remote source address.

sourcePort number

The remote source port.

url object

The URL.