Middlewares - rejetto/hfs GitHub Wiki
A middleware is a mechanism you can add to the server, doing some work on each request.
This can be inside a plugin, but also directly written into Admin > Options > Server code
.
A middleware has the form of a function that receives a Context object as a parameter. The context object contains all information about the http request and the http response.
Basic examples
Setting http header
exports.middleware = ctx => ctx.set('x-my-header', 'some value')
Custom reply to some address
exports.middleware = ctx => {
if (ctx.path === '/some/address')
ctx.body = 'my content'
}
Allow only Chrome as browser
exports.middleware = ctx => ctx.get('user-agent').includes('Chrome') || ctx.socket.destroy()