feat: Add request context middleware for config and dependency injection in hooks (#8480)

This commit is contained in:
Antoine Cormouls
2025-10-14 20:16:31 +02:00
committed by GitHub
parent e704de83e6
commit 64f104e5c5
12 changed files with 219 additions and 29 deletions

View File

@@ -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());