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
The custom
property can be either an external module or a function that accepts at least two parameters : request
and response
.
[!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 promise is resolved to a value (i.e. not undefined
), an internal redirection occurs i.e. the request is going over the mappings again (infinite loops are prevented, see max-redirect
)
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