From f93376c5ddc7e1e05fb46fff4c6f7ea824f571f5 Mon Sep 17 00:00:00 2001 From: web-next-automation Date: Sun, 7 Apr 2024 19:36:19 -0400 Subject: [PATCH] fix: update config reading for NBS Signed-off-by: web-next-automation --- docs/conf/reading.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/conf/reading.md b/docs/conf/reading.md index 976a418905..5f7218479a 100644 --- a/docs/conf/reading.md +++ b/docs/conf/reading.md @@ -141,6 +141,37 @@ from `@backstage/core-plugin-api`. ## Accessing ConfigApi in Backend Plugins -In backend plugins the configuration is passed in via options from the main +### Old Backend System + +In the old backend system plugins, the configuration is passed in via options from the main backend package. See for example [packages/backend/src/plugins/auth.ts](https://github.com/backstage/backstage/blob/244eef851f5aa19f91c7c9b5c12d5df95cf482ca/packages/backend/src/plugins/auth.ts#L23). + +### New Backend System + +In the new backend system, plugins are able to directly access config through dependencies. You can access config like so, + +```ts title="plugins/your-plugin-backend/src/plugin.ts" +export const yourPlugin = createBackendPlugin({ + pluginId: 'yourPlugin', + register(env) { + env.registerInit({ + deps: { + httpRouter: coreServices.httpRouter, + logger: coreServices.logger, + // highlight-next-line + config: coreServices.rootConfig, + }, + async init({ + httpRouter, + logger, + // highlight-next-line + config, + }) { + // highlight-next-line + console.log(config.getOptionalString('backend.test.property')); + }, + }); + }, +}); +```