The Whook base HTTP server
The Whook's httpServer
service is
responsible for instanciating the NodeJS HTTP Server and handling its
start/shutdown.
It can be easily replaced by any other HTTP server (an HTTPS one for instance if you cannot use a gateway or a proxy to handle HTTPS connections).
The server takes in charge graceful shutdown by awaiting connections to be
closed before shutting down which can take a long time (basically if a browser
is still maintaining an open socket with it). You can short circuit this
behavior, basically for development, by setting the DESTROY_SOCKETS=1
environment variable.
-
initHTTPServer(services) ⇒
Promise.<HTTPServer>
-
Initialize an HTTP server
initHTTPServer(services) ⇒ Promise.<HTTPServer>
Initialize an HTTP server
Kind: global function
Returns: Promise.<HTTPServer>
- A promise of an object with a NodeJS HTTP server
in its service
property.
Param | Type | Default | Description |
---|---|---|---|
services | Object |
The services the server depends on | |
[services.ENV] | Object |
The process environment variables | |
services.ENV.DESTROY_SOCKETS | String |
Whether the server sockets whould be destroyed or if the server should wait while sockets are kept alive | |
[services.HTTP_SERVER_OPTIONS] | Object |
See https://nodejs.org/docs/latest/api/http.html#class-httpserver | |
services.HOST | String |
The server host | |
services.PORT | Number |
The server port | |
services.httpRouter | function |
The function to run with the req/res tuple | |
[services.log] | function |
noop |
A logging function |
Kind: global typedef