|
| 1 | +[id="overriding-core-backend-services_{context}"] |
| 2 | += Overriding Core Backend Service Configuration |
| 3 | + |
| 4 | +The {product} ({product-very-short}) backend platform consists of a number of core services that are well encapsulated. |
| 5 | +The {product-very-short} backend installs these default core services statically during initialization. |
| 6 | + |
| 7 | +Customize a core service by installing it as a `BackendFeature` by using the dynamic plugin functionality. |
| 8 | + |
| 9 | +.Procedure |
| 10 | +. Configure {product-short} to allow a core service override, by setting the corresponding core service ID environment variable to `true` in the {product-short} `{my-app-config-file}` configuration file. |
| 11 | ++ |
| 12 | +.Environment variables and core service IDs |
| 13 | +[cols="50%,50%",frame="all",options="header"] |
| 14 | +|=== |
| 15 | +|Variable |
| 16 | +|Overrides the related service |
| 17 | + |
| 18 | +|`ENABLE_CORE_AUTH_OVERRIDE` |
| 19 | +|`core.auth` |
| 20 | + |
| 21 | +| `ENABLE_CORE_CACHE_OVERRIDE` |
| 22 | +| `core.cache` |
| 23 | + |
| 24 | +| `ENABLE_CORE_ROOTCONFIG_OVERRIDE` |
| 25 | +| `core.rootConfig` |
| 26 | + |
| 27 | +| `ENABLE_CORE_DATABASE_OVERRIDE` |
| 28 | +| `core.database` |
| 29 | + |
| 30 | +| `ENABLE_CORE_DISCOVERY_OVERRIDE` |
| 31 | +| `core.discovery` |
| 32 | + |
| 33 | +| `ENABLE_CORE_HTTPAUTH_OVERRIDE` |
| 34 | +| `core.httpAuth` |
| 35 | + |
| 36 | +| `ENABLE_CORE_HTTPROUTER_OVERRIDE` |
| 37 | +| `core.httpRouter` |
| 38 | + |
| 39 | +| `ENABLE_CORE_LIFECYCLE_OVERRIDE` |
| 40 | +| `core.lifecycle` |
| 41 | + |
| 42 | +| `ENABLE_CORE_LOGGER_OVERRIDE` |
| 43 | +| `core.logger` |
| 44 | + |
| 45 | +| `ENABLE_CORE_PERMISSIONS_OVERRIDE` |
| 46 | +| `core.permissions` |
| 47 | + |
| 48 | +| `ENABLE_CORE_ROOTHEALTH_OVERRIDE` |
| 49 | +| `core.rootHealth` |
| 50 | + |
| 51 | +| `ENABLE_CORE_ROOTHTTPROUTER_OVERRIDE` |
| 52 | +| `core.rootHttpRouter` |
| 53 | + |
| 54 | +| `ENABLE_CORE_ROOTLIFECYCLE_OVERRIDE` |
| 55 | +| `core.rootLifecycle` |
| 56 | + |
| 57 | +| `ENABLE_CORE_SCHEDULER_OVERRIDE` |
| 58 | +| `core.scheduler` |
| 59 | + |
| 60 | +| `ENABLE_CORE_USERINFO_OVERRIDE` |
| 61 | +| `core.userInfo` |
| 62 | + |
| 63 | +| `ENABLE_CORE_URLREADER_OVERRIDE` |
| 64 | +| `core.urlReader` |
| 65 | + |
| 66 | +| `ENABLE_EVENTS_SERVICE_OVERRIDE` |
| 67 | +| `events.service` |
| 68 | +|=== |
| 69 | + |
| 70 | +. Install your custom core service as a `BackendFeature` as shown in the following example: |
| 71 | + |
| 72 | +.Example of a `BackendFeature` middleware function to handle incoming `HTTP` requests |
| 73 | +[source,javascript] |
| 74 | +---- |
| 75 | +// Create the BackendFeature |
| 76 | +export const customRootHttpServerFactory: BackendFeature = |
| 77 | + rootHttpRouterServiceFactory({ |
| 78 | + configure: ({ app, routes, middleware, logger }) => { |
| 79 | + logger.info( |
| 80 | + 'Using custom root HttpRouterServiceFactory configure function', |
| 81 | + ); |
| 82 | + app.use(middleware.helmet()); |
| 83 | + app.use(middleware.cors()); |
| 84 | + app.use(middleware.compression()); |
| 85 | + app.use(middleware.logging()); |
| 86 | + // Add a the custom middleware function before all |
| 87 | + // of the route handlers |
| 88 | + app.use(addTestHeaderMiddleware({ logger })); |
| 89 | + app.use(routes); |
| 90 | + app.use(middleware.notFound()); |
| 91 | + app.use(middleware.error()); |
| 92 | + }, |
| 93 | + }); |
| 94 | +
|
| 95 | +// Export the BackendFeature as the default entrypoint |
| 96 | +export default customRootHttpServerFactory; |
| 97 | +---- |
| 98 | ++ |
| 99 | +In the previous example, as the `BackendFeature` overrides the default implementation of the HTTP router service, you must set the `ENABLE_CORE_ROOTHTTPROUTER_OVERRIDE` environment variable to `true` so that the {product-short} does not install the default implementation automatically. |
| 100 | + |
0 commit comments