Middleware
NotifyBC pre-installed following Express middleware as defined in src/middleware.ts
- compression
- helmet
- morgan (disabled by default)
src/middleware.ts contains following default middleware settings
import path from 'path';
module.exports = {
all: {
compression: {},
},
apiOnly: {
helmet: {},
morgan: {
params: [
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status ":req[X-Forwarded-For]"',
],
enabled: false,
},
},
};
src/middleware.ts has following structure
module.exports = {
all: {
'<middlewareName>': {params: [], enabled: <boolean>},
},
apiOnly: {
'<middlewareName>': {params: [], enabled: <boolean>},
},
};
Middleware defined under all applies to both API and web console requests, as opposed to apiOnly, which applies to API requests only. params are passed to middleware function as arguments. enabled toggles the middleware on or off.
To change default settings defined in src/middleware.ts, create file src/middleware.local.ts or src/middleware.<env>.ts to override. For example, to enable access log,
module.exports = {
apiOnly: {
morgan: {
enabled: true,
},
},
};