From 1d124c34352889b12494fc7c1b93715bf94c079b Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Mon, 10 Nov 2025 10:08:41 -0500 Subject: [PATCH] add example router Signed-off-by: aramissennyeydd --- packages/backend/package.json | 3 +- packages/backend/src/index.ts | 1 + packages/backend/src/systemMetadataPlugin.ts | 48 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/systemMetadataPlugin.ts diff --git a/packages/backend/package.json b/packages/backend/package.json index 2af36b8077..3ea09f7540 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -69,7 +69,8 @@ "@opentelemetry/auto-instrumentations-node": "^0.61.0", "@opentelemetry/exporter-prometheus": "^0.54.0", "@opentelemetry/sdk-node": "^0.54.0", - "example-app": "link:../app" + "example-app": "link:../app", + "express-promise-router": "^4.1.0" }, "devDependencies": { "@backstage/cli": "workspace:^" diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 9282c51f22..8f8fd106d6 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -69,6 +69,7 @@ backend.add(searchLoader); backend.add(import('@backstage/plugin-techdocs-backend')); backend.add(import('@backstage/plugin-signals-backend')); backend.add(import('@backstage/plugin-notifications-backend')); +backend.add(import('./systemMetadataPlugin')); backend.add(import('@backstage/plugin-events-backend-module-google-pubsub')); backend.add(import('@backstage/plugin-mcp-actions-backend')); diff --git a/packages/backend/src/systemMetadataPlugin.ts b/packages/backend/src/systemMetadataPlugin.ts new file mode 100644 index 0000000000..434e708073 --- /dev/null +++ b/packages/backend/src/systemMetadataPlugin.ts @@ -0,0 +1,48 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import Router from 'express-promise-router'; + +/** + * Example plugin that shows how to reveal all installed plugins with the + * system metadata API. + */ +export default createBackendPlugin({ + pluginId: 'system-metadata-router', + register: reg => { + reg.registerInit({ + deps: { + systemMetadata: coreServices.rootSystemMetadata, + rootHttpRouter: coreServices.rootHttpRouter, + }, + async init({ systemMetadata, rootHttpRouter }) { + const router = Router(); + router.get('/plugins', async (_, res) => { + const plugins = (await systemMetadata.getInstalledPlugins()).toSorted( + (a, b) => a.pluginId.localeCompare(b.pluginId), + ); + res.json(plugins); + }); + + rootHttpRouter.use('/.backstage/systemMetadata', router); + }, + }); + }, +});