@@ -12,21 +12,34 @@ import { serviceName as modelsServiceName } from "pagopa-interop-models";
12
12
import attributeRouter from "./routers/AttributeRouter.js" ;
13
13
import healthRouter from "./routers/HealthRouter.js" ;
14
14
import { config } from "./config/config.js" ;
15
+ import { AttributeRegistryService } from "./services/attributeRegistryService.js" ;
15
16
16
- const serviceName = modelsServiceName . ATTRIBUTE_REGISTRY_PROCESS ;
17
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
18
+ export async function createApp ( service ?: AttributeRegistryService ) {
19
+ const serviceName = modelsServiceName . ATTRIBUTE_REGISTRY_PROCESS ;
17
20
18
- const app = zodiosCtx . app ( ) ;
21
+ const router =
22
+ service != null
23
+ ? attributeRouter ( zodiosCtx , service )
24
+ : attributeRouter ( zodiosCtx ) ;
19
25
20
- // Disable the "X-Powered-By: Express" HTTP header for security reasons.
21
- // See https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html#recommendation_16
22
- app . disable ( "x-powered-by" ) ;
26
+ const app = zodiosCtx . app ( ) ;
23
27
24
- app . use ( healthRouter ) ;
25
- app . use ( contextMiddleware ( serviceName ) ) ;
26
- app . use ( await applicationAuditBeginMiddleware ( serviceName , config ) ) ;
27
- app . use ( await applicationAuditEndMiddleware ( serviceName , config ) ) ;
28
- app . use ( authenticationMiddleware ( config ) ) ;
29
- app . use ( loggerMiddleware ( serviceName ) ) ;
30
- app . use ( attributeRouter ( zodiosCtx ) ) ;
28
+ // Disable the "X-Powered-By: Express" HTTP header for security reasons.
29
+ // See https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html#recommendation_16
30
+ app . disable ( "x-powered-by" ) ;
31
+
32
+ app . use ( healthRouter ) ;
33
+ app . use ( contextMiddleware ( serviceName ) ) ;
34
+ app . use ( await applicationAuditBeginMiddleware ( serviceName , config ) ) ;
35
+ app . use ( await applicationAuditEndMiddleware ( serviceName , config ) ) ;
36
+ app . use ( authenticationMiddleware ( config ) ) ;
37
+ app . use ( loggerMiddleware ( serviceName ) ) ;
38
+ app . use ( router ) ;
39
+
40
+ return app ;
41
+ }
42
+
43
+ const app = await createApp ( ) ;
31
44
32
45
export default app ;
0 commit comments