What problem does it solve?
Developing Backstage backend plugins involves navigating complex concepts like dependency injection, core services (e.g., httpRouter, database, httpAuth), and ensuring secure-by-default practices. This Skill streamlines the process of building robust APIs and background jobs, reducing boilerplate and complexity.
Core Features & Use Cases
- Specialized Workflows: Step-by-step procedures for creating and configuring backend plugins.
- Best Practices: Production-ready patterns for authentication, validation, error handling, and database usage with Knex.js.
- Golden Path Templates: Copy/paste code snippets for common backend patterns, including API endpoints and scheduled background tasks.
- Use Case: Rapidly scaffold a new Backstage backend plugin, integrate core services like a database and logger, and define a secure API endpoint, ensuring all best practices for testing and scalability are followed.
Quick Start
Example: Define a new Backstage backend plugin with core service dependencies.
This snippet goes into src/plugin.ts after scaffolding.
import { createBackendPlugin, coreServices } from '@backstage/backend-plugin-api';
import { createRouter } from './service/router';
export const examplePlugin = createBackendPlugin({
pluginId: 'example',
register(env) {
env.registerInit({
deps: {
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
database: coreServices.database,
httpAuth: coreServices.httpAuth,
userInfo: coreServices.userInfo,
},
async init({ httpRouter, logger, database, httpAuth, userInfo }) {
const router = await createRouter({ logger, database, httpAuth, userInfo });
httpRouter.use(router);
httpRouter.addAuthPolicy({ path: '/health', allow: 'unauthenticated' });
},
});
},
});
export { examplePlugin as default } from './plugin';