### Create, Add Features, and Start Backend Source: https://backstage.io/docs/next/plugins/new-backend-system This snippet demonstrates the basic setup for creating a Backstage backend instance, installing a catalog backend plugin, and starting the backend. It highlights the simplified process using the new backend system. ```typescript import { createBackend } from '@backstage/backend-defaults'; // Create your backend instance const backend = createBackend(); // Install all desired features backend.add(import('@backstage/plugin-catalog-backend')); // Start up the backend backend.start(); ``` -------------------------------- ### Install and Start Minikube Source: https://backstage.io/docs/next/deployment/k8s Installs minikube using Homebrew and starts a local Kubernetes cluster. This is useful for testing Kubernetes concepts locally before production deployment. ```bash # Assumes Mac + Homebrew; see the minikube site for other installations $ brew install minikube $ minikube start ... Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default. ``` -------------------------------- ### Example CI/CD Script for TechDocs Source: https://backstage.io/docs/next/features/techdocs/configuring-ci-cd A comprehensive example script demonstrating the preparation, installation, generation, and publishing steps for TechDocs in a CI/CD environment. ```bash # This is an example script # Prepare REPOSITORY_URL='https://github.com/org/repo' git clone $REPOSITORY_URL cd repo # Install @techdocs/cli, mkdocs and mkdocs plugins npm install -g @techdocs/cli pip install "mkdocs-techdocs-core==1.*" # Generate techdocs-cli generate --no-docker # Publish techdocs-cli publish --publisher-type awsS3 --storage-name --entity ``` -------------------------------- ### Install a Backend Plugin with Options Source: https://backstage.io/docs/next/plugins/new-backend-system Demonstrates how to install a backend plugin that accepts options, passing the configuration during the installation process. ```typescript backend.add(examplePlugin({ silent: true })); ``` -------------------------------- ### Clone and Prepare Example Todo Plugins Source: https://backstage.io/docs/next/permissions/plugin-authors/01-setup This script clones the example todo list plugins, modifies their package.json files, and renames them to 'todo-list', 'todo-list-backend', and 'todo-list-common'. Ensure you have WSL and git installed if on Windows. ```bash cd $(mktemp -d) git clone --depth 1 --quiet --no-checkout --filter=blob:none https://github.com/backstage/backstage.git . git checkout master -- plugins/example-todo-list/ git checkout master -- plugins/example-todo-list-backend/ git checkout master -- plugins/example-todo-list-common/ sed -i '' 's/workspace:\^/\*/g' plugins/example-todo-list/package.json sed -i '' 's/workspace:\^/\*/g' plugins/example-todo-list-backend/package.json sed -i '' 's/workspace:\^/\*/g' plugins/example-todo-list-common/package.json for file in plugins/*; do mv "$file" "$OLDPWD/${file/example-todo/todo}"; done cd - ``` -------------------------------- ### Basic Scaffolder Plugin Installation Source: https://backstage.io/docs/next/backend-system/building-backends/migrating Installs the basic Scaffolder backend plugin. This is the minimal setup for the plugin. ```typescript const backend = createBackend(); backend.add(import('@backstage/plugin-scaffolder-backend')); ``` -------------------------------- ### Install Processor Using New Backend System Source: https://backstage.io/docs/next/features/software-catalog/external-integrations Example of creating and registering a backend module for the SystemXReaderProcessor using the new backend system in packages/backend/src/index.ts. ```typescript import { createBackend } from '@backstage/backend-defaults'; import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node'; import { SystemXReaderProcessor } from '../path/to/class'; export const catalogModuleSystemXReaderProcessor = createBackendModule({ pluginId: 'catalog', moduleId: 'system-x-reader-processor', register(env) { env.registerInit({ deps: { catalog: catalogProcessingExtensionPoint, reader: coreServices.urlReader, }, async init({ catalog, reader }) { catalog.addProcessor(new SystemXReaderProcessor(reader)); }, }); }, }); const backend = createBackend(); backend.add(import('@backstage/plugin-catalog-backend')); backend.add(catalogModuleSystemXReaderProcessor); // Other plugins ... backend.start(); ``` -------------------------------- ### Minimal Backstage App Instance Source: https://backstage.io/docs/next/frontend-system/building-apps/index Create a minimal Backstage app instance using `createApp` from `@backstage/frontend-defaults`. This example installs the catalog plugin and uses default settings. ```typescript import ReactDOM from 'react-dom/client'; import { createApp } from '@backstage/frontend-defaults'; import catalogPlugin from '@backstage/plugin-catalog/alpha'; import '@backstage/ui/css/styles.css'; // Create your app instance const app = createApp({ // Custom features such as plugins can be installed explicitly, but they are usually // auto-discovered, unless `app.packages` is customized in `app-config.yaml`. features: [catalogPlugin], }); // This creates a React element that renders the entire app const root = app.createRoot(); // Just like any other React we need a root element. No server side rendering is used. const rootEl = document.getElementById('root')!; ReactDOM.createRoot(rootEl).render(root); ``` -------------------------------- ### New Backend Index File - Initial Setup Source: https://backstage.io/docs/next/backend-system/building-backends/migrating The minimal structure for a new Backstage backend index file using `@backstage/backend-defaults`. This version starts with a blank service. ```typescript import { createBackend } from '@backstage/backend-defaults'; const backend = createBackend(); backend.start(); ``` -------------------------------- ### Create Backend Feature Loader Example Source: https://backstage.io/docs/next/releases/v1.30.0-changelog Demonstrates how to create an installable backend feature loader that can dynamically load other backend features. Supports generator functions for asynchronous loading and allows dependency injection of root-scoped services. ```typescript const searchLoader = createBackendFeatureLoader({ deps: { config: coreServices.rootConfig, }, *loader({ config }) { // Example of a custom config flag to enable search if (config.getOptionalString('customFeatureToggle.search')) { yield import('@backstage/plugin-search-backend/alpha'); yield import('@backstage/plugin-search-backend-module-catalog/alpha'); yield import('@backstage/plugin-search-backend-module-explore/alpha'); yield import('@backstage/plugin-search-backend-module-techdocs/alpha'); } }, }); ``` -------------------------------- ### Setup Mock Service Worker with a GET request Source: https://backstage.io/docs/next/architecture-decisions/adrs-adr007 This snippet demonstrates how to set up MSW with a basic GET request handler. It defines a worker that intercepts requests to '*/user/:userId' and responds with JSON data. The worker is then started. ```typescript import { setupWorker, rest } from 'msw'; const worker = setupWorker( rest.get('*/user/:userId', (req, res, ctx) => { return res( ctx.json({ firstName: 'John', lastName: 'Maverick', }), ); }), ); // Start the Mock Service Worker worker.start(); ``` -------------------------------- ### Full Backend Startup Configuration Reference Source: https://backstage.io/docs/next/backend-system/building-backends/index Reference for all backend startup configuration options, including global defaults and per-plugin/module overrides for boot failure handling. ```yaml backend: startup: # Global defaults applied when not specified per-plugin or per-module default: # Defaults to 'abort'. Set to 'continue' to make all plugins optional by default. onPluginBootFailure: abort # or continue # Defaults to 'abort'. Set to 'continue' to make all plugin modules optional by default. onPluginModuleBootFailure: abort # or continue # Per-plugin and per-module overrides plugins: : # Override the default boot failure behavior for this specific plugin. onPluginBootFailure: abort # or continue modules: : # Override the default boot failure behavior for this specific plugin module. onPluginModuleBootFailure: abort # or continue ``` -------------------------------- ### List Actions API Endpoint Source: https://backstage.io/docs/next/features/software-templates/api/list-actions This is the GET endpoint for retrieving all installed actions. It returns a JSON array of action objects, each with an ID, description, examples, and schema for input and output. ```HTTP GET ## //v2/actions ``` -------------------------------- ### Example Backstage Configuration File Source: https://backstage.io/docs/next/conf/writing A sample app-config.yaml file demonstrating common configuration sections like app, backend, organization, and proxy settings. ```yaml app: title: Backstage Example App baseUrl: http://localhost:3000 backend: listen: 0.0.0.0:7007 baseUrl: http://localhost:7007 organization: name: CNCF proxy: /my/api: target: https://example.com/api/ changeOrigin: true pathRewrite: ^/proxy/my/api/: / ``` -------------------------------- ### Confirm Package Installation Source: https://backstage.io/docs/next/getting-started When prompted during the initial setup, confirm the installation of necessary packages by entering 'y'. ```bash Need to install the following packages: @backstage/create-app@ ok to proceed? (y) ``` -------------------------------- ### Serve TechDocs Site with MkDocs Parameters Source: https://backstage.io/docs/next/features/techdocs/cli Starts the local TechDocs preview, passing specific parameters to the MkDocs server running within the Docker container. Options include `--clean`, `--dirtyreload`, and `--strict`. ```bash techdocs-cli serve --mkdocs-parameter-clean ``` ```bash techdocs-cli serve --mkdocs-parameter-dirtyreload ``` ```bash techdocs-cli serve --mkdocs-parameter-strict ``` -------------------------------- ### New 'repo start' command for @backstage/cli Source: https://backstage.io/docs/next/releases/v1.38.0-next.2-changelog Introduces the 'repo start' command in @backstage/cli to standardize local development startup, replacing 'yarn dev' scripts. ```json { "scripts": { "start": "backstage-cli repo start" } } ``` -------------------------------- ### Create and Start a Basic Backend Instance Source: https://backstage.io/docs/next/backend-system/architecture/backends This snippet demonstrates how to create a backend instance, add catalog and scaffolder plugins, and start the backend. It uses the `createBackend` function for a batteries-included approach. ```typescript import { createBackend } from '@backstage/backend-defaults'; import scaffolderPlugin from '@backstage/plugin-scaffolder-backend'; // Create your backend instance const backend = createBackend(); // Install desired features backend.add(import('@backstage/plugin-catalog-backend')); // Features can also be installed using an explicit reference backend.add(scaffolderPlugin); // Start up the backend backend.start(); ``` -------------------------------- ### TechInsightsBackend code example with scheduler Source: https://backstage.io/docs/next/releases/v1.4.0-changelog This code example for `TechInsightsBackend` includes the missing 'scheduler' dependency, demonstrating a more complete setup. ```typescript const techInsightsBackend = await TechInsightsBackend.fromConfig(config, { logger, database: postgresDatabase, scheduler: taskScheduler, }); ``` -------------------------------- ### Run All Migration Steps (TL;DR) Source: https://backstage.io/docs/next/tutorials/package-role-migration Execute all migration steps sequentially for a quick migration. Ensure you have the latest @backstage/cli installed before running. ```bash yarn backstage-cli migrate package-roles yarn backstage-cli migrate package-scripts yarn backstage-cli migrate package-lint-configs ``` -------------------------------- ### Using the Cache Service in a Backend Plugin Source: https://backstage.io/docs/next/backend-system/core-services/cache Example of how to get a cache client within a backend plugin and perform set and get operations. ```typescript import { coreServices, createBackendPlugin, } from '@backstage/backend-plugin-api'; createBackendPlugin({ pluginId: 'example', register(env) { env.registerInit({ deps: { cache: coreServices.cache, }, async init({ cache }) { const { key, value } = { key: 'test:key', value: 'bob' }; await cache.set(key, value, { ttl: 1000 }); // .. some other stuff. await cache.get(key); // 'bob' }, }); }, }); ``` -------------------------------- ### Basic Auth Plugin Installation with Microsoft Provider Source: https://backstage.io/docs/next/backend-system/building-backends/migrating Installs the basic Auth backend plugin and the Microsoft provider module. This is the minimal setup for using Microsoft authentication. ```typescript const backend = createBackend(); backend.add(import('@backstage/plugin-auth-backend')); backend.add(import('@backstage/plugin-auth-backend-module-microsoft-provider')); ``` -------------------------------- ### Install Frontend Module in Backstage App Source: https://backstage.io/docs/next/frontend-system/architecture/extension-overrides This example shows how to install a frontend module, which overrides the search page, into a Backstage application. It imports the module and includes it in the app's features. ```typescript import { createApp } from '@backstage/frontend-defaults'; import searchPageModule from '@internal/search-page'; const app = createApp({ features: [searchPageModule], }); export default app.createRoot(); ``` -------------------------------- ### Start Local Backstage Development Server Source: https://backstage.io/docs/next/golden-path/create-app/local-development Navigate to your Backstage app directory and run this command to start both the frontend and backend development servers. ```bash cd my-backstage-app # your app name yarn start ``` -------------------------------- ### Example Backend Directory Structure for Splitting Source: https://backstage.io/docs/next/backend-system/building-backends/index Illustrates a potential directory structure when splitting a Backstage backend into multiple packages, such as 'backend-a' and 'backend-b'. ```bash packages/ backend-a/ src/ index.ts package.json <- "name": "backend-a" backend-b/ src/ index.ts package.json <- "name": "backend-b" ``` -------------------------------- ### Integrate Custom Rule Setup into Backend Source: https://backstage.io/docs/next/permissions/custom-rules This snippet demonstrates how to include the custom permission rules module into the main backend setup. This ensures the custom rules are loaded when the Backstage instance starts. ```typescript // catalog plugin backend.add(import('@backstage/plugin-catalog-backend')); backend.add( import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'), ); backend.add(import('./extensions/catalogPermissionRules')); ``` -------------------------------- ### Start the Backstage Application Source: https://backstage.io/docs/next/getting-started Run this command in the application's root directory to start both the frontend and backend processes. ```bash yarn start ``` -------------------------------- ### Get Location by Entity API Request Example (JavaScript Fetch) Source: https://backstage.io/docs/next/features/software-catalog/api/get-location-by-entity Demonstrates how to make a GET request to the /locations/by-entity endpoint using the Fetch API in JavaScript. Ensure you replace '' with a valid JWT. ```javascript const myHeaders = new Headers(); myHeaders.append("Accept", "application/json"); myHeaders.append("Authorization", "Bearer "); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; fetch("/locations/by-entity/:kind/:namespace/:name", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` -------------------------------- ### Build and Serve Backstage App Locally Source: https://backstage.io/docs/next/tutorials/enable-public-entry--old Commands to build the app package and start the backend for local testing of the public entry point configuration. Ensure you are in your project's root folder before running these commands. ```bash # building the app package yarn workspace app start # starting the backend api yarn start-backend ``` -------------------------------- ### Get Task by ID - Success Response Example Source: https://backstage.io/docs/next/features/software-templates/api/get-task Example JSON response for a successfully retrieved task, including its ID, spec, status, creation timestamp, and optional fields like secrets and state. ```json { "id": "string", "spec": {}, "status": "cancelled", "createdAt": "string", "lastHeartbeatAt": "string", "createdBy": "string", "secrets": { "backstageToken": "string" }, "state": {} } ``` -------------------------------- ### Serve TechDocs Site with Docker Options Source: https://backstage.io/docs/next/features/techdocs/cli Starts the local TechDocs preview using Docker, passing additional options to the `docker run` command. This can be used to add host entries or other configurations. ```bash techdocs-cli serve --docker-option "--add-host=internal.host:192.168.11.12" ``` -------------------------------- ### Get Location by ID Response Source: https://backstage.io/docs/next/features/software-catalog/software-catalog-api Example response structure for retrieving a specific catalog location by its ID. ```json { "id": "b9784c38-7118-472f-9e22-5638fc73bab0", "target": "https://git.example.com/example-project/example-repository/blob/main/catalog-info.yaml", "type": "url" } ``` -------------------------------- ### Install Dependencies, Generate Types, and Build Backend Source: https://backstage.io/docs/next/deployment/docker These commands are executed from the root of the Backstage repository to prepare the backend for Docker image creation. They ensure dependencies are installed immutably, type definitions are generated, and the backend is built. ```bash yarn install --immutable # tsc outputs type definitions to dist-types/ in the repo root, which are then consumed by the build yarn tsc # Build the backend, which bundles it all up into the packages/backend/dist folder. yarn build:backend ``` -------------------------------- ### Install Dependencies, Compile, and Build Backend Source: https://backstage.io/docs/next/golden-path/deployment/docker Run these commands from the root of your repository to prepare for building the Docker image. This involves installing dependencies, compiling TypeScript, and building the backend. ```bash yarn install yarn tsc yarn build:backend ``` -------------------------------- ### GET /v2/actions Source: https://backstage.io/docs/next/features/software-templates/api/list-actions Returns a list of all installed actions. This endpoint is secured with HTTP Bearer Token authentication. ```APIDOC ## GET /v2/actions ### Description Returns a list of all installed actions. This endpoint is secured with HTTP Bearer Token authentication. ### Method GET ### Endpoint /v2/actions ### Parameters #### Query Parameters None #### Request Body None ### Responses #### Success Response (200) - **id** (string) - Required - Unique identifier for the action. - **description** (string) - Description of the action. - **examples** (object[]) - An array of examples for the action. - **description** (string) - Required - Description of the example. - **example** (string) - Required - The example itself. - **schema** (object) - Schema defining the input and output of the action. - **input** (object) - Schema for the action's input. - **output** (object) - Schema for the action's output. #### Response Example ```json [ { "id": "string", "description": "string", "examples": [ { "description": "string", "example": "string" } ], "schema": { "input": {}, "output": {} } } ] ``` #### Authorization - **name:** JWT - **type:** http - **scheme:** bearer - **bearerFormat:** JWT ``` -------------------------------- ### Kubernetes Configuration Example Source: https://backstage.io/docs/next/features/kubernetes/configuration A full example of the app-config.yaml entry for configuring the Kubernetes integration, including cluster details and frontend options. ```yaml kubernetes: frontend: podDelete: enabled: true serviceLocatorMethod: type: 'multiTenant' clusterLocatorMethods: - type: 'config' clusters: - url: http://127.0.0.1:9999 name: minikube authProvider: 'serviceAccount' skipTLSVerify: false skipMetricsLookup: true serviceAccountToken: ${K8S_MINIKUBE_TOKEN} dashboardUrl: http://127.0.0.1:64713 # url copied from running the command: minikube service kubernetes-dashboard -n kubernetes-dashboard dashboardApp: standard caData: ${K8S_CONFIG_CA_DATA} caFile: '' # local path to CA file customResources: - group: 'argoproj.io' apiVersion: 'v1alpha1' plural: 'rollouts' - url: http://127.0.0.2:9999 name: aws-cluster-1 title: 'My AWS Cluster Number One' authProvider: 'aws' - type: 'gke' projectId: 'gke-clusters' region: 'europe-west1' skipTLSVerify: true skipMetricsLookup: true exposeDashboard: true ``` -------------------------------- ### Get name and relations collection Source: https://backstage.io/docs/next/features/software-catalog/api/get-entities-by-query Example demonstrating how to retrieve the 'name' field and the entire 'relations' collection for entities. ```HTTP /entities/by-query?fields=metadata.name,relations ``` -------------------------------- ### Configure GitHub Integration Source: https://backstage.io/docs/next/integrations Example configuration for integrating with GitHub. This setup requires a GITHUB_TOKEN environment variable for authentication. ```yaml integrations: github: - host: github.com token: ${GITHUB_TOKEN} ``` -------------------------------- ### Serve TechDocs Site with Custom MkDocs Config File Source: https://backstage.io/docs/next/features/techdocs/cli Starts the local TechDocs preview, specifying a custom YAML file for MkDocs configuration. ```bash techdocs-cli serve -c ``` -------------------------------- ### Start Backstage App Source: https://backstage.io/docs/next/getting-started/config/database Command to start the Backstage application after configuration. ```bash yarn start ``` -------------------------------- ### Integrate Search Backend Plugins Source: https://backstage.io/docs/next/features/search/getting-started Add the installed search backend plugins and modules to your backend application's setup. ```typescript const backend = createBackend(); // Other plugins... // search plugin backend.add(import('@backstage/plugin-search-backend')); // search engines backend.add(import('@backstage/plugin-search-backend-module-pg')); // search collators backend.add(import('@backstage/plugin-search-backend-module-catalog')); backend.add(import('@backstage/plugin-search-backend-module-techdocs')); backend.start(); ``` -------------------------------- ### Retrieve entity ref components Source: https://backstage.io/docs/next/features/software-catalog/api/get-entities-by-query Example of using the `fields` parameter to get only the necessary data to form the full reference of each entity. ```HTTP /entities/by-query?fields=kind,metadata.namespace,metadata.name ``` -------------------------------- ### Install @backstage/frontend-plugin-api Source: https://backstage.io/docs/next/frontend-system/building-apps/migrating Install the necessary package for creating custom frontend modules and extensions. ```bash yarn --cwd packages/app add @backstage/frontend-plugin-api ``` -------------------------------- ### Get All Kubernetes Pods Source: https://backstage.io/docs/next/deployment/k8s Lists all pods across all namespaces in the minikube cluster. Useful for verifying that pods are running after starting the cluster. ```bash $ kubectl get pods -A ``` -------------------------------- ### Loading Configuration Files Source: https://backstage.io/docs/next/golden-path/deployment/config-first Demonstrates how to load multiple configuration files, with later files overriding earlier ones. This is typically used for base and production configurations. ```bash node packages/backend --config app-config.yaml --config app-config.production.yaml ``` -------------------------------- ### Create a New Backend Module Source: https://backstage.io/docs/next/features/software-catalog/external-integrations Use the Backstage CLI to scaffold a new backend module for catalog extensions. ```bash yarn new --select backend-module --option pluginId=catalog ``` -------------------------------- ### Create a Fake Plugin-Scoped Service Source: https://backstage.io/docs/next/backend-system/core-services/plugin-metadata Example of a fake plugin-scoped service using the plugin metadata service to get the plugin ID. ```typescript import { coreServices, createServiceFactory, } from '@backstage/backend-plugin-api'; export const myServiceFactory = createServiceFactory({ service: myServiceRef, deps: { logger: coreServices.logger, plugin: coreServices.pluginMetadata, }, async factory({ logger, plugin }) { const pluginId = plugin.getId(); logger.info(`Creating an instance of my service for plugin '${id}'`); return ...; // TODO }, }); ``` -------------------------------- ### Serve TechDocs Site Locally Source: https://backstage.io/docs/next/features/techdocs/cli Starts a local preview of the TechDocs site within a Backstage-like environment. By default, it uses Docker to manage dependencies. ```bash techdocs-cli serve ``` -------------------------------- ### Basic Test Permission Policy Source: https://backstage.io/docs/next/permissions/writing-a-policy A minimal example of a permission policy that always allows authorization. This serves as a starting point for more complex policies. ```typescript class TestPermissionPolicy implements PermissionPolicy { async handle(): Promise { return { result: AuthorizeResult.ALLOW }; } } ``` -------------------------------- ### Recommended root package.json scripts for @backstage/cli migration Source: https://backstage.io/docs/next/releases/v1.38.0-next.2-changelog Recommended additional scripts for the root package.json to aid migration to the new 'yarn start' command in @backstage/cli. ```json { "scripts": { "dev": "echo \"Use 'yarn start' instead\"", "start-backend": "echo \"Use 'yarn start backend' instead\"" } } ``` -------------------------------- ### Observe Shortcuts with useObservable Source: https://backstage.io/docs/next/releases/v1.5.0-changelog Example of how to get and observe shortcuts using the `shortcutsApiRef` and `useObservable` hook. This is useful for initializing shortcuts when using Firestore. ```typescript const shortcutApi = useApi(shortcutsApiRef); const shortcuts = useObservable(shortcutApi.shortcut$(), shortcutApi.get()); ``` -------------------------------- ### Add Custom Frontend Module with Extensions Source: https://backstage.io/docs/next/frontend-system/building-apps/migrating Use `createFrontendModule` to bundle custom extensions into a feature for installation in the app. This example adds a `lightTheme` extension. ```typescript import { createFrontendModule } from '@backstage/frontend-plugin-api'; const app = createApp({ features: [ // ... createFrontendModule({ pluginId: 'app', extensions: [lightTheme], }), ], }); ``` -------------------------------- ### Minimal Backstage Backend Setup Source: https://backstage.io/docs/next/backend-system/building-backends/index This is a minimal Backstage backend setup using `createBackend` and adding essential plugins. It demonstrates the basic structure of a backend package. ```typescript import { createBackend } from '@backstage/backend-defaults'; const backend = createBackend(); backend.add(import('@backstage/plugin-app-backend')); backend.add(import('@backstage/plugin-catalog-backend')); backend.add(import('@backstage/plugin-scaffolder-backend')); backend.add( import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model') ); backend.start(); ``` -------------------------------- ### Install a Backend Plugin Source: https://backstage.io/docs/next/plugins/new-backend-system Shows how to add a created backend plugin to the Backstage backend system. ```typescript backend.add(examplePlugin); ``` -------------------------------- ### Install OpenAPI Catalog Backend Module Source: https://backstage.io/docs/next/features/software-catalog/configuration Installs the @backstage/plugin-catalog-backend-module-openapi package for OpenAPI and AsyncAPI placeholder support. ```bash yarn --cwd packages/backend add @backstage/plugin-catalog-backend-module-openapi ``` -------------------------------- ### Accessing ConfigApi in Backend Plugins Source: https://backstage.io/docs/next/conf/reading In the backend, access configuration through dependency injection by registering `coreServices.rootConfig`. This example shows how to get an optional string property. ```typescript export const yourPlugin = createBackendPlugin({ pluginId: 'yourPlugin', register(env) { env.registerInit({ deps: { httpRouter: coreServices.httpRouter, logger: coreServices.logger, config: coreServices.rootConfig, }, async init({ httpRouter, logger, config, }) { console.log(config.getOptionalString('backend.test.property')); }, }); }, }); ``` -------------------------------- ### Create a Basic Development Backend Source: https://backstage.io/docs/next/backend-system/building-plugins-and-modules/migrating Sets up a minimal development backend for running a plugin locally. Ensure `@backstage/backend-defaults` is installed as a dev dependency. ```typescript import { createBackend } from '@backstage/backend-defaults'; const backend = createBackend(); // Path to the file where the plugin is export as default backend.add(import('../src')); backend.start(); ``` -------------------------------- ### Replace Default TemplateCard Component Source: https://backstage.io/docs/next/features/software-templates/configuration Register a `SwappableComponentBlueprint` extension to replace the default `TemplateCard` in the new frontend system. This example shows the setup in `appModuleScaffolder.tsx`. ```typescript // packages/app/src/modules/appModuleScaffolder.tsx import { createFrontendModule } from '@backstage/frontend-plugin-api'; import { SwappableComponentBlueprint } from '@backstage/plugin-app-react'; import { TemplateCard } from '@backstage/plugin-scaffolder-react/alpha'; export const appModuleScaffolder = createFrontendModule({ pluginId: 'app', extensions: [ SwappableComponentBlueprint.make({ name: 'scaffolder-template-card', params: defineParams => defineParams({ component: TemplateCard, loader: () => import('./MyTemplateCard').then(m => m.MyTemplateCard), }), }), ], }); ``` -------------------------------- ### Install a Plugin Instance Source: https://backstage.io/docs/next/backend-system/architecture/plugins Shows how to add a plugin instance to the backend using its exported factory function. ```typescript import { examplePlugin } from 'backstage-plugin-example-backend'; backend.add(examplePlugin); ```