Skip to content

Commit 0a76425

Browse files
committed
RHIDP-6502 Overriding Core Backend Service Configuration
Signed-off-by: Fabrice Flore-Thébault <[email protected]>
1 parent f5ac51b commit 0a76425

File tree

3 files changed

+106
-102
lines changed

3 files changed

+106
-102
lines changed

assemblies/dynamic-plugins/assembly-configuring-rhdh-plugins.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ include::../assembly-using-servicenow.adoc[leveloffset=+1]
3131
include::../assembly-using-kubernetes-custom-actions.adoc[leveloffset=+1]
3232

3333
// Overriding Core Backend Service Configuration
34-
include::../modules/dynamic-plugins/con-overriding-core-backend-services.adoc[leveloffset=+1]
34+
include::../modules/dynamic-plugins/proc-overriding-core-backend-services.adoc[leveloffset=+1]

modules/dynamic-plugins/con-overriding-core-backend-services.adoc

Lines changed: 0 additions & 101 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 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 set 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`.
71+
+
72+
For example,
73+
adding a middleware function to handle all incoming requests can be done
74+
by installing a custom `configure` function for the root `HTTP` router backend service
75+
which allows access to the underlying Express application.
76+
+
77+
.Example of a `BackendFeature` middleware function to handle incoming `HTTP` requests
78+
[source,javascript]
79+
----
80+
// Create the BackendFeature
81+
export const customRootHttpServerFactory: BackendFeature =
82+
rootHttpRouterServiceFactory({
83+
configure: ({ app, routes, middleware, logger }) => {
84+
logger.info(
85+
'Using custom root HttpRouterServiceFactory configure function',
86+
);
87+
app.use(middleware.helmet());
88+
app.use(middleware.cors());
89+
app.use(middleware.compression());
90+
app.use(middleware.logging());
91+
// Add a the custom middleware function before all
92+
// of the route handlers
93+
app.use(addTestHeaderMiddleware({ logger }));
94+
app.use(routes);
95+
app.use(middleware.notFound());
96+
app.use(middleware.error());
97+
},
98+
});
99+
100+
// Export the BackendFeature as the default entrypoint
101+
export default customRootHttpServerFactory;
102+
----
103+
+
104+
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.
105+

0 commit comments

Comments
 (0)