mirror of
https://github.com/appy-one/acebase-server.git
synced 2026-06-30 06:02:05 -06:00
21 lines
No EOL
857 B
JavaScript
21 lines
No EOL
857 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.addMiddleware = void 0;
|
|
const addMiddleware = (env) => {
|
|
env.app.use((req, res, next) => {
|
|
// Setup AceBase context, to allow clients to pass contextual info with data updates,
|
|
// that will be sent along to data event subscribers on affected data.
|
|
const context = req.get('AceBase-Context') || '{}';
|
|
try {
|
|
req.context = JSON.parse(context);
|
|
}
|
|
catch (err) {
|
|
env.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
|
|
return res.status(500).end('Invalid request context');
|
|
}
|
|
next();
|
|
});
|
|
};
|
|
exports.addMiddleware = addMiddleware;
|
|
exports.default = exports.addMiddleware;
|
|
//# sourceMappingURL=context.js.map
|