Backstage Backend Defaults is a comprehensive TypeScript library that provides default implementations and service factories for Backstage backend applications. It serves as a batteries-included foundation for building backend services with standardized authentication, database connectivity, HTTP routing, logging, caching, discovery, scheduling, and more.
yarn add @backstage/backend-defaultsimport { createBackend } from "@backstage/backend-defaults";For specific service factories:
import { authServiceFactory } from "@backstage/backend-defaults/auth";
import { databaseServiceFactory } from "@backstage/backend-defaults/database";
import { loggerServiceFactory } from "@backstage/backend-defaults/logger";import { createBackend } from "@backstage/backend-defaults";
// Create a backend with all default service factories pre-configured
const backend = createBackend();
// Add your plugins
backend.add(import('@backstage/plugin-catalog-backend'));
backend.add(import('@backstage/plugin-scaffolder-backend'));
// Start the backend
await backend.start();Backstage Backend Defaults is built around several key architectural components:
The main API for creating a complete Backstage backend instance with all default services pre-configured.
/**
* Creates a Backend instance with all default service factories pre-configured
* @returns Backend instance ready for plugin installation
*/
function createBackend(): Backend;
/**
* Discovers backend features from package.json and dependencies
*/
const discoveryFeatureLoader: FeatureLoader;Comprehensive collection of service factories for all core backend services including authentication, database, logging, and more.
// Authentication services
const authServiceFactory: ServiceFactory;
const httpAuthServiceFactory: ServiceFactory;
// Database services
const databaseServiceFactory: ServiceFactory;
// Logging and monitoring
const loggerServiceFactory: ServiceFactory;
const rootLoggerServiceFactory: ServiceFactory;
const auditorServiceFactory: ServiceFactory;
// HTTP and routing
const httpRouterServiceFactory: ServiceFactory;
const rootHttpRouterServiceFactory: ServiceFactory;HTTP server creation, routing, middleware, and authentication utilities for building REST APIs and web interfaces.
/**
* Creates an HTTP server instance
*/
function createHttpServer(options: HttpServerOptions): ExtendedHttpServer;
/**
* Creates router for authentication integrations
*/
function createAuthIntegrationRouter(): Router;
/**
* Creates middleware for credentials validation
*/
function createCredentialsBarrier(): RequestHandler;
interface HttpServerOptions {
listen?: { port?: number; host?: string };
https?: HttpServerCertificateOptions | boolean;
}Database connection management, migrations, and URL readers for various storage providers and source control systems.
class DatabaseManager {
forPlugin(pluginId: string): Promise<Knex>;
}
interface DatabaseManagerOptions {
migrations?: { skip?: boolean };
}
// URL readers for different providers
class GithubUrlReader implements UrlReader;
class GitlabUrlReader implements UrlReader;
class AwsS3UrlReader implements UrlReader;
class AzureBlobStorageUrlReader implements UrlReader;Authentication services, permissions, and user information management for secure backend operations.
class DefaultHttpAuthService implements HttpAuthService;
interface DefaultHttpAuthServiceOptions {
defaultCredentials?: BackstageCredentials;
}
interface PluginTokenHandler {
verifyToken(token: string): Promise<BackstageCredentials>;
}
const permissionsServiceFactory: ServiceFactory;
const userInfoServiceFactory: ServiceFactory;Authentication and Authorization
Caching, scheduling, discovery, logging implementations, and configuration utilities.
class CacheManager {
getClient(options?: CacheManagerOptions): Promise<CacheClient>;
}
class DefaultSchedulerService implements SchedulerService;
class HostDiscovery implements DiscoveryService {
constructor(options: HostDiscoveryOptions);
}
interface HostDiscoveryOptions {
basePath?: string;
endpoints?: HostDiscoveryEndpoint[];
}