@metreeca/gate - v0.12.0
    Preparing search index...

    Type Alias ServerOpts

    HTTP server options.

    Configures where Server.listen accepts connections, how it identifies the resources it serves, which forwarded caller addresses it trusts and how it shuts down. Every option may be omitted: the defaults suit a server exposed directly to clients on a free port, serving resources under the host each request was received on.

    type ServerOpts = {
        host?: string;
        port?: number;
        base?: string;
        proxies?: number;
        grace?: number;
        signal?: AbortSignal;
    }
    Index

    Properties

    host?: string

    The address the server listens on, containing no whitespace; if omitted or empty, the server listens on every interface, over IPv4 and IPv6 alike, as containers and hosting platforms require of a server they expose.

    Set it to localhost to keep a local server unreachable from the network.

    port?: number

    The port the server listens on, from 0 to 65535; if omitted or 0, the server listens on a free port assigned by the operating system, and the port actually used is logged once the server is listening.

    base?: string

    The canonical absolute hierarchical IRI of the service, identifying the resources it serves wherever the server runs; if omitted, resources are identified by the scheme and host each request was received on.

    Drivers resolve request paths against it, keeping the IRIs of stored resources stable across deployments.

    Resolution follows RFC 3986, as for the relative IRIs in queries and bodies: request paths are root-relative, so the base contributes its scheme and authority, and any path it holds is replaced. With the base below, a request for /products/1 addresses https://data.example.com/products/1, whatever host the server itself runs on.

    server(store).listen({ base: "https://data.example.com/" })
    
    proxies?: number

    The number of proxy hops in front of the server whose forwarded caller address is trusted; defaults to 0.

    Trusted hops let routes see the address of the caller rather than that of a proxy. The default trusts no forwarded address, as fits a server exposed directly, where clients could otherwise forge their address.

    Set it to the number of proxies in front of the server, for instance 1 behind the front-end proxy of a hosting platform, or 2 behind a load balancer in front of that proxy. A count above the actual number of proxies trusts an address supplied by the client itself, which lets clients forge their address again as if no proxy existed.

    grace?: number

    The milliseconds granted to the requests in flight to complete when the server closes; 0, the default, sets no limit of its own and leaves the limit to the hosting platform, which may kill the process before requests end.

    Requests still running at the end of the period have their connections closed. Set it below the period the hosting platform allows between the termination signal and a forced kill, so that the server exits cleanly.

    signal?: AbortSignal

    A signal that closes the server when aborted, as SIGINT or SIGTERM would. A signal that is already aborted when listen() is called closes the server as soon as it starts listening, and the returned promise resolves.