Class: Application

Application

A Freon application.

Constructor

new Application(domainsopt, notFoundPageopt, notFoundPageHeadersopt, maxClientBytes)

Creates a new Freon application.
Parameters:
Name Type Attributes Default Description
domains Array.<string> | Array.<RegExp> <optional>
The list of domains to listen on (ex. `['example.com', /.+\.example.com/]`).
notFoundPage string | BufferType <optional>
'' The data to be served when no handlers were found.
notFoundPageHeaders Object.<string, string> <optional>
{'Content-Type':'text/plain'} The headers to send when no handlers were found.
maxClientBytes number The maximum number of bytes that the client is allowed to send in the body before the connection is destroyed. Use this to prevent denial of service attacks. By default, it is left undefined, allowing an infinite number of bytes.
Properties:
Name Type Description
notFoundPage string | BufferType The data to be served when no handlers were found.
notFoundPageHeaders Object.<string, string> The headers to send when no handlers were found.
handlers Object The applications' handlers.
Source:

Methods

listen(port, callbackopt, httpsPortopt, httpsOptionsopt, hostnameopt)

Starts the server.
Parameters:
Name Type Attributes Description
port Number The port to host the HTTP server on.
callback function <optional>
What to call back to when the server starts.
httpsPort Number <optional>
The port to host the HTTPS server on.
httpsOptions Object <optional>
The 'key' and 'cert' to use in PEM format or the 'pfx' data to use. See https://nodejs.org/docs/latest-v5.x/api/https.html#https_https_createserver_options_requestlistener.
hostname String <optional>
Only accept connections from this IP address. When omitted, connections from all IP addresses are handled.
Source:

on(options, callback)

Adds a handler. For example: myApp.on({ 'path' : /\/.+\//, 'method' : 'GET' }, (req, res) => { // Code... });
Parameters:
Name Type Description
options handler Options object.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

onAny(path, callback)

Adds a handler for any request method. Simply calls the `on` method.
Parameters:
Name Type Description
path string | RegExp The path to listen for.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

onDelete(path, callback)

Adds a handler for a PUT request. Simply calls the `on` method.
Parameters:
Name Type Description
path string | RegExp The path to listen for.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

onGet(path, callback)

Adds a handler for a GET request. Simply calls the `on` method.
Parameters:
Name Type Description
path string | RegExp The path to listen for.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

onPost(path, callback)

Adds a handler for a POST request. Simply calls the `on` method.
Parameters:
Name Type Description
path string | RegExp The path to listen for.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

onPut(path, callback)

Adds a handler for a PUT request. Simply calls the `on` method.
Parameters:
Name Type Description
path string | RegExp The path to listen for.
callback handlerCallback What to call back to when a request is made to this handler.
Source:

plugin(plugin)

Adds a plugin to the application.
Parameters:
Name Type Description
plugin function The function to be called to load this plugin on a request.
Source:

testRequest(req, res)

Should only be used for testing. Sends a 'fake' request.
Parameters:
Name Type Description
req Object The request.
res Object The response.
Source: