feat: Add request context middleware for config and dependency injection in hooks (#8480)
This commit is contained in:
@@ -279,6 +279,18 @@ class ParseServer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* Allow developers to customize each request with inversion of control/dependency injection
|
||||
*/
|
||||
static applyRequestContextMiddleware(api, options) {
|
||||
if (options.requestContextMiddleware) {
|
||||
if (typeof options.requestContextMiddleware !== 'function') {
|
||||
throw new Error('requestContextMiddleware must be a function');
|
||||
}
|
||||
api.use(options.requestContextMiddleware);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @static
|
||||
* Create an express app for the parse server
|
||||
@@ -326,7 +338,7 @@ class ParseServer {
|
||||
middlewares.addRateLimit(route, options);
|
||||
}
|
||||
api.use(middlewares.handleParseSession);
|
||||
|
||||
this.applyRequestContextMiddleware(api, options);
|
||||
const appRouter = ParseServer.promiseRouter({ appId });
|
||||
api.use(appRouter.expressRouter());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user