custom
handlerEnables custom handlers.
{
custom: async (request, response) => response.setHeader('X-Server', 'REserve')
}
Example of embedded mapping with the
custom
handler
{
custom: './xserver.js'
}
Example of mapping with the
custom
handler
module.exports = async (request, response) => response.('X-Server', 'REserve')
Corresponding
xserver.js
file
{
custom: () => [
'<html><title>Not found</title></html>',
{
statusCode :404
}
]
}
Example of
custom
mapping sending back a response (new to version 2.1.0)
{
custom: [
'<html><title>Not found</title></html>',
{
statusCode :404
}
]
}
Example of
custom
mapping sending back a response (new to version 2.2.0)
The custom
property can be:
function
,function
that accepts at least two parameters : request
and response
,array
, the two first values are passed to send
to finalize the response.When custom
is a function
:
[!IMPORTANT] Only if the function’s length is
0
or greater than2
The function is invoked with the current mapping being used as this
During the initialization, the current mapping’s member named configuration
is set to the configuration interface
[!CAUTION] It overwrites any existing member with the same name
The function may return a Promise
If the function returns (or returns a promise resolving to) a string
or a number
, an internal redirection occurs, i.e. the request is going over the mappings again (infinite loops are prevented, see max-redirect
)
With version 2.1.0, if the function returns (or returns a promise resolving to) an array
, the two first values are passed to send
to finalize the response.
If the response
is not finalized after executing the function (i.e. response.end
was not called), the request
is going over the remaining mappings