diff --git a/docs/backend-system/building-plugins-and-modules/02-testing.md b/docs/backend-system/building-plugins-and-modules/02-testing.md index 570048f0cb..7d2b6e019d 100644 --- a/docs/backend-system/building-plugins-and-modules/02-testing.md +++ b/docs/backend-system/building-plugins-and-modules/02-testing.md @@ -36,8 +36,10 @@ describe('myPlugin', () => { const fakeConfig = { myPlugin: { value: 7 } }; const { server } = await startTestBackend({ - features: [myPlugin()], - services: [mockServices.rootConfig.factory({ data: fakeConfig })], + features: [ + myPlugin(), + mockServices.rootConfig.factory({ data: fakeConfig }), + ], }); const response = await request(server).get('/api/example/get-value'); @@ -150,8 +152,10 @@ your test database. ```ts const { knex, subject } = await createSubject(databaseId); const { server } = await startTestBackend({ - features: [myPlugin()], - services: [[coreServices.database, { getClient: async () => knex }]], + features: [ + myPlugin(), + mockServices.database.mock({ getClient: async () => knex }), + ], }); ``` diff --git a/docs/backend-system/core-services/01-index.md b/docs/backend-system/core-services/01-index.md index 8877b89320..baed9a2cdc 100644 --- a/docs/backend-system/core-services/01-index.md +++ b/docs/backend-system/core-services/01-index.md @@ -61,13 +61,13 @@ You can configure these additional options by adding an override for the core se ```ts import { httpRouterServiceFactory } from '@backstage/backend-app-api'; -const backend = createBackend({ - services: [ - httpRouterServiceFactory({ - getPath: (pluginId: string) => `/plugins/${pluginId}`, - }), - ], -}); +const backend = createBackend(); + +backend.add( + httpRouterServiceFactory({ + getPath: (pluginId: string) => `/plugins/${pluginId}`, + }), +); ``` ## Root HTTP Router @@ -118,28 +118,28 @@ You can configure the root HTTP Router service by passing the options to the `cr ```ts import { rootHttpRouterServiceFactory } from '@backstage/backend-app-api'; -const backend = createBackend({ - services: [ - rootHttpRouterServiceFactory({ - configure: ({ app, middleware, routes, config, logger, lifecycle }) => { - // the built in middleware is provided through an option in the configure function - app.use(middleware.helmet()); - app.use(middleware.cors()); - app.use(middleware.compression()); +const backend = createBackend(); - // you can add you your own middleware in here - app.use(custom.logging()); +backend.add( + rootHttpRouterServiceFactory({ + configure: ({ app, middleware, routes, config, logger, lifecycle }) => { + // the built in middleware is provided through an option in the configure function + app.use(middleware.helmet()); + app.use(middleware.cors()); + app.use(middleware.compression()); - // here the routes that are registered by other plugins - app.use(routes); + // you can add you your own middleware in here + app.use(custom.logging()); - // some other middleware that comes after the other routes - app.use(middleware.notFound()); - app.use(middleware.error()); - }, - }), - ], -}); + // here the routes that are registered by other plugins + app.use(routes); + + // some other middleware that comes after the other routes + app.use(middleware.notFound()); + app.use(middleware.error()); + }, + }), +); ``` ## Root Config @@ -185,19 +185,19 @@ You can configure these additional options by adding an override for the core se ```ts import { rootConfigServiceFactory } from '@backstage/backend-app-api'; -const backend = createBackend({ - services: [ - rootConfigServiceFactory({ - argv: [ - '--config', - '/backstage/app-config.development.yaml', - '--config', - '/backstage/app-config.yaml', - ], - remote: { reloadIntervalSeconds: 60 }, - }), - ], -}); +const backend = createBackend(); + +backend.add( + rootConfigServiceFactory({ + argv: [ + '--config', + '/backstage/app-config.development.yaml', + '--config', + '/backstage/app-config.yaml', + ], + remote: { reloadIntervalSeconds: 60 }, + }), +); ``` ## Logging @@ -243,34 +243,34 @@ The following example is how you can override the root logger service to add add import { coreServices } from '@backstage/backend-plugin-api'; import { WinstonLogger } from '@backstage/backend-app-api'; -const backend = createBackend({ - services: [ - createServiceFactory({ - service: coreServices.rootLogger, - deps: { - config: coreServices.rootConfig, - }, - async factory({ config }) { - const logger = WinstonLogger.create({ - meta: { - service: 'backstage', - // here's some additional information that is not part of the - // original implementation - podName: 'myk8spod', - }, - level: process.env.LOG_LEVEL || 'info', - format: - process.env.NODE_ENV === 'production' - ? format.json() - : WinstonLogger.colorFormat(), - transports: [new transports.Console()], - }); +const backend = createBackend(); - return logger; - }, - }), - ], -}); +backend.add( + createServiceFactory({ + service: coreServices.rootLogger, + deps: { + config: coreServices.rootConfig, + }, + async factory({ config }) { + const logger = WinstonLogger.create({ + meta: { + service: 'backstage', + // here's some additional information that is not part of the + // original implementation + podName: 'myk8spod', + }, + level: process.env.LOG_LEVEL || 'info', + format: + process.env.NODE_ENV === 'production' + ? format.json() + : WinstonLogger.colorFormat(), + transports: [new transports.Console()], + }); + + return logger; + }, + }), +); ``` ## Cache @@ -440,14 +440,14 @@ You can configure these additional options by adding an override for the core se ```ts import { identityServiceFactory } from '@backstage/backend-app-api'; -const backend = createBackend({ - services: [ - identityServiceFactory({ - issuer: 'backstage', - algorithms: ['ES256', 'RS256'], - }), - ], -}); +const backend = createBackend(); + +backend.add( + identityServiceFactory({ + issuer: 'backstage', + algorithms: ['ES256', 'RS256'], + }), +); ``` ## Lifecycle @@ -532,19 +532,19 @@ class MyCustomLifecycleService implements RootLifecycleService { } } -const backend = createBackend({ - services: [ - createServiceFactory({ - service: coreServices.rootLifecycle, - deps: { - logger: coreServices.rootLogger, - }, - async factory({ logger }) { - return new MyCustomLifecycleService(logger); - }, - }), - ], -}); +const backend = createBackend(); + +backend.add( + createServiceFactory({ + service: coreServices.rootLifecycle, + deps: { + logger: coreServices.rootLogger, + }, + async factory({ logger }) { + return new MyCustomLifecycleService(logger); + }, + }), +); ``` ## Permissions diff --git a/docs/plugins/new-backend-system.md b/docs/plugins/new-backend-system.md index 2ff061a60b..0023584d0d 100644 --- a/docs/plugins/new-backend-system.md +++ b/docs/plugins/new-backend-system.md @@ -266,12 +266,10 @@ class GoogleCloudLogger implements LoggerService { } // packages/backend/src/index.ts -const backend = createBackend({ - services: [ - // supplies additional or replacement services to the backend - GoogleCloudLogger.factory(), - ], -}); +const backend = createBackend(); + +// supplies additional or replacement services to the backend +backend.add(GoogleCloudLogger.factory()); ``` ## Testing