|
| 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. The {product-very-short} backend installs these default core services statically during initialization. |
| 5 | + |
| 6 | +You can configure these core services by customizing the backend source code and rebuilding your {product-short} application. Alternatively, you can customize a core service by installing it as a `BackendFeature` by using dynamic plugin functionality. |
| 7 | + |
| 8 | +To use dynamic plugin functionality to customize a core service in your RHDH application, you must configure the backend to avoid statically installing a given default core service |
| 9 | + |
| 10 | +For example, adding a middleware function to handle all incoming requests can be done by installing a custom `configure` function for the root `HTTP` router backend service which allows access to the underlying Express application. |
| 11 | + |
| 12 | +.Example of a `BackendFeature` middleware function to handle incoming `HTTP` requests |
| 13 | + |
| 14 | +[source,javascript] |
| 15 | +---- |
| 16 | +// Create the BackendFeature |
| 17 | +export const customRootHttpServerFactory: BackendFeature = |
| 18 | + rootHttpRouterServiceFactory({ |
| 19 | + configure: ({ app, routes, middleware, logger }) => { |
| 20 | + logger.info( |
| 21 | + 'Using custom root HttpRouterServiceFactory configure function', |
| 22 | + ); |
| 23 | + app.use(middleware.helmet()); |
| 24 | + app.use(middleware.cors()); |
| 25 | + app.use(middleware.compression()); |
| 26 | + app.use(middleware.logging()); |
| 27 | + // Add a the custom middleware function before all |
| 28 | + // of the route handlers |
| 29 | + app.use(addTestHeaderMiddleware({ logger })); |
| 30 | + app.use(routes); |
| 31 | + app.use(middleware.notFound()); |
| 32 | + app.use(middleware.error()); |
| 33 | + }, |
| 34 | + }); |
| 35 | +
|
| 36 | +// Export the BackendFeature as the default entrypoint |
| 37 | +export default customRootHttpServerFactory; |
| 38 | +---- |
| 39 | + |
| 40 | +In the above 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. |
| 41 | + |
| 42 | +== Overriding environment variables |
| 43 | +To allow a dynamic plugin to load a core service override, you must start the {product-short} backend with the corresponding core service ID environment variable set to `true`. |
| 44 | + |
| 45 | +.Environment variables and core service IDs |
| 46 | +[cols="50%,50%", frame="all", options="header"] |
| 47 | +|=== |
| 48 | +|Variable |
| 49 | +|Description |
| 50 | + |
| 51 | +|`ENABLE_CORE_AUTH_OVERRIDE` |
| 52 | +|Override the `core.auth` service |
| 53 | + |
| 54 | +| `ENABLE_CORE_CACHE_OVERRIDE` |
| 55 | +| Override the `core.cache` service |
| 56 | + |
| 57 | +| `ENABLE_CORE_ROOTCONFIG_OVERRIDE` |
| 58 | +| Override the `core.rootConfig` service |
| 59 | + |
| 60 | +| `ENABLE_CORE_DATABASE_OVERRIDE` |
| 61 | +| Override the `core.database` service |
| 62 | + |
| 63 | +| `ENABLE_CORE_DISCOVERY_OVERRIDE` |
| 64 | +| Override the `core.discovery` service |
| 65 | + |
| 66 | +| `ENABLE_CORE_HTTPAUTH_OVERRIDE` |
| 67 | +| Override the `core.httpAuth` service |
| 68 | + |
| 69 | +| `ENABLE_CORE_HTTPROUTER_OVERRIDE` |
| 70 | +| Override the `core.httpRouter` service |
| 71 | + |
| 72 | +| `ENABLE_CORE_LIFECYCLE_OVERRIDE` |
| 73 | +| Override the `core.lifecycle` service |
| 74 | + |
| 75 | +| `ENABLE_CORE_LOGGER_OVERRIDE` |
| 76 | +| Override the `core.logger` service |
| 77 | + |
| 78 | +| `ENABLE_CORE_PERMISSIONS_OVERRIDE` |
| 79 | +| Override the `core.permissions` service |
| 80 | + |
| 81 | +| `ENABLE_CORE_ROOTHEALTH_OVERRIDE` |
| 82 | +| Override the `core.rootHealth` service |
| 83 | + |
| 84 | +| `ENABLE_CORE_ROOTHTTPROUTER_OVERRIDE` |
| 85 | +| Override the `core.rootHttpRouter` service |
| 86 | + |
| 87 | +| `ENABLE_CORE_ROOTLIFECYCLE_OVERRIDE` |
| 88 | +| Override the `core.rootLifecycle` service |
| 89 | + |
| 90 | +| `ENABLE_CORE_SCHEDULER_OVERRIDE` |
| 91 | +| Override the `core.scheduler` service |
| 92 | + |
| 93 | +| `ENABLE_CORE_USERINFO_OVERRIDE` |
| 94 | +| Override the `core.userInfo` service |
| 95 | + |
| 96 | +| `ENABLE_CORE_URLREADER_OVERRIDE` |
| 97 | +| Override the `core.urlReader` service |
| 98 | + |
| 99 | +| `ENABLE_EVENTS_SERVICE_OVERRIDE` |
| 100 | +| Override the `events.service` service |
| 101 | +|=== |
0 commit comments