Log Server Action in Rest requests
MODIFY
src/server/rest/RestServer.ts
src/server/rest/RestServer.ts
@@ -28,20 +28,18 @@ export default class RestServer {
this.expressApplication.use(AuthService.initialize());
// Routers
this.expressApplication.use('/v1', new GlobalRouterV1().buildRoutes());
- // Secured API
+ // TODO: To Remove, Secured API is deprecated
this.expressApplication.use('/client/api/:action',
AuthService.authenticate(),
SessionHashService.checkUserAndTenantValidity.bind(this),
- async (req: Request, res: Response, next: NextFunction) => Logging.traceExpressRequest(req, res, next),
RestServerService.restServiceSecured.bind(this)
);
- // Util API
+ // TODO: To Remove, Util API is deprecated
this.expressApplication.use('/client/util/:action',
- async (req: Request, res: Response, next: NextFunction) => Logging.traceExpressRequest(req, res, next),
RestServerService.restServiceUtil.bind(this)
);
// Post init
- ExpressUtils.postInitApplication(this.expressApplication);
+ ExpressUtils.postInitApplication(this.expressApplication, false);
// Create HTTP server to serve the express app
RestServer.restHttpServer = ServerUtils.createHttpServer(RestServer.centralSystemRestConfig, this.expressApplication);
}

MODIFY
src/server/rest/v1/router/GlobalRouterV1.ts
src/server/rest/v1/router/GlobalRouterV1.ts
@@ -50,7 +50,6 @@ export default class GlobalRouterV1 {
this.router.use('/api',
AuthService.authenticate(),
SessionHashService.checkUserAndTenantValidity.bind(this),
- async (req: Request, res: Response, next: NextFunction) => Logging.traceExpressRequest(req, res, next),
[
new AssetRouter().buildRoutes(),
new BillingRouter().buildRoutes(),

MODIFY
src/utils/RouterUtils.ts
src/utils/RouterUtils.ts
@@ -12,7 +12,12 @@ export default class RouterUtils {
handleMethod: (serverAction: ServerAction, req: Request, res: Response, next: NextFunction) => Promise<void>,
serverAction: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
try {
+ // Trace Request
+ await Logging.traceExpressRequest(req, res, next, serverAction);
+ // Process
await handleMethod(serverAction, req, res, next);
+ // Trace Response
+ Logging.traceExpressResponse(req, res, next, serverAction);
} catch (error) {
next(error);
Utils.isDevelopmentEnv() && Logging.logConsoleError(error.stack);

Log Server Action in Rest requests