preRouting
Specify a function or a string containing an absolute path to a module that exports a function.
The function executes upon the server receiving any HTTP request before any other logic acts on the request, including internal Profound.js code.
When called, the function will receive the following 3 parameters:
request - the HTTP request object, which can be read to decide what to do.
response - the HTTP response object before it gets sent to the client.
next - a function that must be called if other logic should handle the request. If next() is not called, then no other, internal Profound.js code will issue a response to the client.
The module is loaded upon server startup and cached like any Node.js module.
preRouting is expected to behave as “middleware” intended for the popular Node.js HTTP server package, Express.
Example 1
config.js setting:
// Send an additional header that allows content to be inside of iframes when the parent iframe is the PJS server.
preRouting: function(request, response, next) {
response.setHeader("Content-Security-Policy", "frame-ancestors " + profound.settings.host);
next(); // Mandatory: let other logic process the request so that a response will eventually be issued.
}
Example 2
config.js setting:
preRouting: path.join("var", "profoundjs", "preRouting.js")
Content of preRouting.js:
module.exports = function(request, response, next) {
response.setHeader("Content-Security-Policy", "frame-ancestors " + profound.settings.host);
next();
};
Click here for information on how to modify this setting.
The preRouting configuration option is available in Profound.js versions after 7.4.0.