@backstage/backend-app-api 0.3.2-next.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @backstage/backend-app-api might be problematic. Click here for more details.

package/dist/index.cjs.js CHANGED
@@ -295,7 +295,7 @@ function readHttpsOptions(config) {
295
295
  }
296
296
  return {
297
297
  certificate: {
298
- type: "plain",
298
+ type: "pem",
299
299
  cert: cc.getString("certificate.cert"),
300
300
  key: cc.getString("certificate.key")
301
301
  }
@@ -898,16 +898,14 @@ var __privateSet$4 = (obj, member, value, setter) => {
898
898
  return value;
899
899
  };
900
900
  var _isCalled, _shutdownTasks;
901
- const CALLBACKS = ["SIGTERM", "SIGINT", "beforeExit"];
902
901
  class BackendLifecycleImpl {
903
902
  constructor(logger) {
904
903
  this.logger = logger;
905
904
  __privateAdd$4(this, _isCalled, false);
906
905
  __privateAdd$4(this, _shutdownTasks, []);
907
- CALLBACKS.map((signal) => process.on(signal, () => this.shutdown()));
908
906
  }
909
- addShutdownHook(options) {
910
- __privateGet$4(this, _shutdownTasks).push(options);
907
+ addShutdownHook(hook, options) {
908
+ __privateGet$4(this, _shutdownTasks).push({ hook, options });
911
909
  }
912
910
  async shutdown() {
913
911
  if (__privateGet$4(this, _isCalled)) {
@@ -916,10 +914,11 @@ class BackendLifecycleImpl {
916
914
  __privateSet$4(this, _isCalled, true);
917
915
  this.logger.info(`Running ${__privateGet$4(this, _shutdownTasks).length} shutdown tasks...`);
918
916
  await Promise.all(
919
- __privateGet$4(this, _shutdownTasks).map(async (hook) => {
920
- const { logger = this.logger } = hook;
917
+ __privateGet$4(this, _shutdownTasks).map(async ({ hook, options }) => {
918
+ var _a;
919
+ const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
921
920
  try {
922
- await hook.fn();
921
+ await hook();
923
922
  logger.info(`Shutdown hook succeeded`);
924
923
  } catch (error) {
925
924
  logger.error(`Shutdown hook failed, ${error}`);
@@ -930,7 +929,7 @@ class BackendLifecycleImpl {
930
929
  }
931
930
  _isCalled = new WeakMap();
932
931
  _shutdownTasks = new WeakMap();
933
- const rootLifecycleFactory = backendPluginApi.createServiceFactory({
932
+ const rootLifecycleServiceFactory = backendPluginApi.createServiceFactory({
934
933
  service: backendPluginApi.coreServices.rootLifecycle,
935
934
  deps: {
936
935
  logger: backendPluginApi.coreServices.rootLogger
@@ -962,78 +961,63 @@ var __privateMethod$2 = (obj, member, method) => {
962
961
  __accessCheck$3(obj, member, "access private method");
963
962
  return method;
964
963
  };
965
- var _started, _features, _registerInits, _extensionPoints, _serviceHolder, _getInitDeps, getInitDeps_fn, _resolveInitOrder, resolveInitOrder_fn;
964
+ var _startPromise, _features, _registerInits, _extensionPoints, _serviceHolder, _getInitDeps, getInitDeps_fn, _doStart, doStart_fn, _resolveInitOrder, resolveInitOrder_fn;
966
965
  class BackendInitializer {
967
966
  constructor(serviceHolder) {
968
967
  __privateAdd$3(this, _getInitDeps);
968
+ __privateAdd$3(this, _doStart);
969
969
  __privateAdd$3(this, _resolveInitOrder);
970
- __privateAdd$3(this, _started, false);
971
- __privateAdd$3(this, _features, /* @__PURE__ */ new Map());
970
+ __privateAdd$3(this, _startPromise, void 0);
971
+ __privateAdd$3(this, _features, new Array());
972
972
  __privateAdd$3(this, _registerInits, new Array());
973
973
  __privateAdd$3(this, _extensionPoints, /* @__PURE__ */ new Map());
974
974
  __privateAdd$3(this, _serviceHolder, void 0);
975
975
  __privateSet$3(this, _serviceHolder, serviceHolder);
976
976
  }
977
- add(feature, options) {
978
- if (__privateGet$3(this, _started)) {
977
+ add(feature) {
978
+ if (__privateGet$3(this, _startPromise)) {
979
979
  throw new Error("feature can not be added after the backend has started");
980
980
  }
981
- __privateGet$3(this, _features).set(feature, options);
981
+ if (feature.$$type !== "@backstage/BackendFeature") {
982
+ throw new Error(
983
+ `Failed to add feature, invalid type '${feature.$$type}'`
984
+ );
985
+ }
986
+ const internalFeature = feature;
987
+ if (internalFeature.version !== "v1") {
988
+ throw new Error(
989
+ `Failed to add feature, invalid version '${internalFeature.version}'`
990
+ );
991
+ }
992
+ __privateGet$3(this, _features).push(internalFeature);
982
993
  }
983
994
  async start() {
984
- if (__privateGet$3(this, _started)) {
995
+ if (__privateGet$3(this, _startPromise)) {
985
996
  throw new Error("Backend has already started");
986
997
  }
987
- __privateSet$3(this, _started, true);
988
- for (const ref of __privateGet$3(this, _serviceHolder).getServiceRefs()) {
989
- if (ref.scope === "root") {
990
- await __privateGet$3(this, _serviceHolder).get(ref, "root");
991
- }
992
- }
993
- for (const [feature] of __privateGet$3(this, _features)) {
994
- const provides = /* @__PURE__ */ new Set();
995
- let registerInit = void 0;
996
- feature.register({
997
- registerExtensionPoint: (extensionPointRef, impl) => {
998
- if (registerInit) {
999
- throw new Error("registerExtensionPoint called after registerInit");
1000
- }
1001
- if (__privateGet$3(this, _extensionPoints).has(extensionPointRef)) {
1002
- throw new Error(`API ${extensionPointRef.id} already registered`);
1003
- }
1004
- __privateGet$3(this, _extensionPoints).set(extensionPointRef, impl);
1005
- provides.add(extensionPointRef);
1006
- },
1007
- registerInit: (registerOptions) => {
1008
- if (registerInit) {
1009
- throw new Error("registerInit must only be called once");
1010
- }
1011
- registerInit = {
1012
- id: feature.id,
1013
- provides,
1014
- consumes: new Set(Object.values(registerOptions.deps)),
1015
- deps: registerOptions.deps,
1016
- init: registerOptions.init
1017
- };
1018
- }
1019
- });
1020
- if (!registerInit) {
1021
- throw new Error(
1022
- `registerInit was not called by register in ${feature.id}`
1023
- );
998
+ const exitHandler = async () => {
999
+ process.removeListener("SIGTERM", exitHandler);
1000
+ process.removeListener("SIGINT", exitHandler);
1001
+ process.removeListener("beforeExit", exitHandler);
1002
+ try {
1003
+ await this.stop();
1004
+ process.exit(0);
1005
+ } catch (error) {
1006
+ console.error(error);
1007
+ process.exit(1);
1024
1008
  }
1025
- __privateGet$3(this, _registerInits).push(registerInit);
1026
- }
1027
- const orderedRegisterResults = __privateMethod$2(this, _resolveInitOrder, resolveInitOrder_fn).call(this, __privateGet$3(this, _registerInits));
1028
- for (const registerInit of orderedRegisterResults) {
1029
- const deps = await __privateMethod$2(this, _getInitDeps, getInitDeps_fn).call(this, registerInit.deps, registerInit.id);
1030
- await registerInit.init(deps);
1031
- }
1009
+ };
1010
+ process.addListener("SIGTERM", exitHandler);
1011
+ process.addListener("SIGINT", exitHandler);
1012
+ process.addListener("beforeExit", exitHandler);
1013
+ __privateSet$3(this, _startPromise, __privateMethod$2(this, _doStart, doStart_fn).call(this));
1014
+ await __privateGet$3(this, _startPromise);
1032
1015
  }
1033
1016
  async stop() {
1034
- if (!__privateGet$3(this, _started)) {
1017
+ if (!__privateGet$3(this, _startPromise)) {
1035
1018
  return;
1036
1019
  }
1020
+ await __privateGet$3(this, _startPromise);
1037
1021
  const lifecycleService = await __privateGet$3(this, _serviceHolder).get(
1038
1022
  backendPluginApi.coreServices.rootLifecycle,
1039
1023
  "root"
@@ -1045,7 +1029,7 @@ class BackendInitializer {
1045
1029
  }
1046
1030
  }
1047
1031
  }
1048
- _started = new WeakMap();
1032
+ _startPromise = new WeakMap();
1049
1033
  _features = new WeakMap();
1050
1034
  _registerInits = new WeakMap();
1051
1035
  _extensionPoints = new WeakMap();
@@ -1080,6 +1064,41 @@ getInitDeps_fn = async function(deps, pluginId) {
1080
1064
  }
1081
1065
  return Object.fromEntries(result);
1082
1066
  };
1067
+ _doStart = new WeakSet();
1068
+ doStart_fn = async function() {
1069
+ for (const ref of __privateGet$3(this, _serviceHolder).getServiceRefs()) {
1070
+ if (ref.scope === "root") {
1071
+ await __privateGet$3(this, _serviceHolder).get(ref, "root");
1072
+ }
1073
+ }
1074
+ for (const feature of __privateGet$3(this, _features)) {
1075
+ for (const r of feature.getRegistrations()) {
1076
+ const provides = /* @__PURE__ */ new Set();
1077
+ if (r.type === "plugin") {
1078
+ for (const [extRef, extImpl] of r.extensionPoints) {
1079
+ if (__privateGet$3(this, _extensionPoints).has(extRef)) {
1080
+ throw new Error(
1081
+ `ExtensionPoint with ID '${extRef.id}' is already registered`
1082
+ );
1083
+ }
1084
+ __privateGet$3(this, _extensionPoints).set(extRef, extImpl);
1085
+ provides.add(extRef);
1086
+ }
1087
+ }
1088
+ __privateGet$3(this, _registerInits).push({
1089
+ id: r.type === "plugin" ? r.pluginId : `${r.pluginId}.${r.moduleId}`,
1090
+ provides,
1091
+ consumes: new Set(Object.values(r.init.deps)),
1092
+ init: r.init
1093
+ });
1094
+ }
1095
+ }
1096
+ const orderedRegisterResults = __privateMethod$2(this, _resolveInitOrder, resolveInitOrder_fn).call(this, __privateGet$3(this, _registerInits));
1097
+ for (const registerInit of orderedRegisterResults) {
1098
+ const deps = await __privateMethod$2(this, _getInitDeps, getInitDeps_fn).call(this, registerInit.init.deps, registerInit.id);
1099
+ await registerInit.init.func(deps);
1100
+ }
1101
+ };
1083
1102
  _resolveInitOrder = new WeakSet();
1084
1103
  resolveInitOrder_fn = function(registerInits) {
1085
1104
  let registerInitsToOrder = registerInits.slice();
@@ -1128,6 +1147,23 @@ var __privateMethod$1 = (obj, member, method) => {
1128
1147
  return method;
1129
1148
  };
1130
1149
  var _providedFactories, _loadedDefaultFactories, _implementations, _rootServiceImplementations, _resolveFactory, resolveFactory_fn, _checkForMissingDeps, checkForMissingDeps_fn;
1150
+ function toInternalServiceFactory(factory) {
1151
+ const f = factory;
1152
+ if (f.$$type !== "@backstage/ServiceFactory") {
1153
+ throw new Error(`Invalid service factory, bad type '${f.$$type}'`);
1154
+ }
1155
+ if (f.version !== "v1") {
1156
+ throw new Error(`Invalid service factory, bad version '${f.version}'`);
1157
+ }
1158
+ return f;
1159
+ }
1160
+ const pluginMetadataServiceFactory = backendPluginApi.createServiceFactory(
1161
+ (options) => ({
1162
+ service: backendPluginApi.coreServices.pluginMetadata,
1163
+ deps: {},
1164
+ factory: async () => ({ getId: () => options.pluginId })
1165
+ })
1166
+ );
1131
1167
  class ServiceRegistry {
1132
1168
  constructor(factories) {
1133
1169
  __privateAdd$2(this, _resolveFactory);
@@ -1136,7 +1172,9 @@ class ServiceRegistry {
1136
1172
  __privateAdd$2(this, _loadedDefaultFactories, void 0);
1137
1173
  __privateAdd$2(this, _implementations, void 0);
1138
1174
  __privateAdd$2(this, _rootServiceImplementations, /* @__PURE__ */ new Map());
1139
- __privateSet$2(this, _providedFactories, new Map(factories.map((f) => [f.service.id, f])));
1175
+ __privateSet$2(this, _providedFactories, new Map(
1176
+ factories.map((sf) => [sf.service.id, toInternalServiceFactory(sf)])
1177
+ ));
1140
1178
  __privateSet$2(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
1141
1179
  __privateSet$2(this, _implementations, /* @__PURE__ */ new Map());
1142
1180
  }
@@ -1146,7 +1184,7 @@ class ServiceRegistry {
1146
1184
  get(ref, pluginId) {
1147
1185
  var _a;
1148
1186
  return (_a = __privateMethod$1(this, _resolveFactory, resolveFactory_fn).call(this, ref, pluginId)) == null ? void 0 : _a.then((factory) => {
1149
- if (factory.scope === "root") {
1187
+ if (factory.service.scope === "root") {
1150
1188
  let existing = __privateGet$2(this, _rootServiceImplementations).get(factory);
1151
1189
  if (!existing) {
1152
1190
  __privateMethod$1(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
@@ -1161,7 +1199,7 @@ class ServiceRegistry {
1161
1199
  rootDeps.push(target.then((impl) => [name, impl]));
1162
1200
  }
1163
1201
  existing = Promise.all(rootDeps).then(
1164
- (entries) => factory.factory(Object.fromEntries(entries))
1202
+ (entries) => factory.factory(Object.fromEntries(entries), void 0)
1165
1203
  );
1166
1204
  __privateGet$2(this, _rootServiceImplementations).set(factory, existing);
1167
1205
  }
@@ -1223,12 +1261,9 @@ _rootServiceImplementations = new WeakMap();
1223
1261
  _resolveFactory = new WeakSet();
1224
1262
  resolveFactory_fn = function(ref, pluginId) {
1225
1263
  if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
1226
- return Promise.resolve({
1227
- scope: "plugin",
1228
- service: backendPluginApi.coreServices.pluginMetadata,
1229
- deps: {},
1230
- factory: async () => ({ getId: () => pluginId })
1231
- });
1264
+ return Promise.resolve(
1265
+ toInternalServiceFactory(pluginMetadataServiceFactory({ pluginId }))
1266
+ );
1232
1267
  }
1233
1268
  let resolvedFactory = __privateGet$2(this, _providedFactories).get(ref.id);
1234
1269
  const { __defaultFactory: defaultFactory } = ref;
@@ -1239,7 +1274,7 @@ resolveFactory_fn = function(ref, pluginId) {
1239
1274
  let loadedFactory = __privateGet$2(this, _loadedDefaultFactories).get(defaultFactory);
1240
1275
  if (!loadedFactory) {
1241
1276
  loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
1242
- (f) => typeof f === "function" ? f() : f
1277
+ (f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
1243
1278
  );
1244
1279
  __privateGet$2(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
1245
1280
  }
@@ -1336,7 +1371,7 @@ function createSpecializedBackend(options) {
1336
1371
  return new BackstageBackend(services);
1337
1372
  }
1338
1373
 
1339
- const cacheFactory = backendPluginApi.createServiceFactory({
1374
+ const cacheServiceFactory = backendPluginApi.createServiceFactory({
1340
1375
  service: backendPluginApi.coreServices.cache,
1341
1376
  deps: {
1342
1377
  config: backendPluginApi.coreServices.config,
@@ -1346,25 +1381,28 @@ const cacheFactory = backendPluginApi.createServiceFactory({
1346
1381
  return backendCommon.CacheManager.fromConfig(config);
1347
1382
  },
1348
1383
  async factory({ plugin }, manager) {
1349
- return manager.forPlugin(plugin.getId());
1384
+ return manager.forPlugin(plugin.getId()).getClient();
1350
1385
  }
1351
1386
  });
1352
1387
 
1353
- const configFactory = backendPluginApi.createServiceFactory({
1354
- service: backendPluginApi.coreServices.config,
1355
- deps: {},
1356
- async factory({}, options) {
1357
- const { argv = process.argv, remote } = options != null ? options : {};
1358
- const { config } = await loadBackendConfig({ argv, remote });
1359
- return config;
1360
- }
1361
- });
1388
+ const configServiceFactory = backendPluginApi.createServiceFactory(
1389
+ (options) => ({
1390
+ service: backendPluginApi.coreServices.config,
1391
+ deps: {},
1392
+ async factory({}) {
1393
+ const { argv = process.argv, remote } = options != null ? options : {};
1394
+ const { config } = await loadBackendConfig({ argv, remote });
1395
+ return config;
1396
+ }
1397
+ })
1398
+ );
1362
1399
 
1363
- const databaseFactory = backendPluginApi.createServiceFactory({
1400
+ const databaseServiceFactory = backendPluginApi.createServiceFactory({
1364
1401
  service: backendPluginApi.coreServices.database,
1365
1402
  deps: {
1366
1403
  config: backendPluginApi.coreServices.config,
1367
- plugin: backendPluginApi.coreServices.pluginMetadata
1404
+ lifecycle: backendPluginApi.coreServices.lifecycle,
1405
+ pluginMetadata: backendPluginApi.coreServices.pluginMetadata
1368
1406
  },
1369
1407
  async createRootContext({ config: config$1 }) {
1370
1408
  return config$1.getOptional("backend.database") ? backendCommon.DatabaseManager.fromConfig(config$1) : backendCommon.DatabaseManager.fromConfig(
@@ -1375,12 +1413,15 @@ const databaseFactory = backendPluginApi.createServiceFactory({
1375
1413
  })
1376
1414
  );
1377
1415
  },
1378
- async factory({ plugin }, databaseManager) {
1379
- return databaseManager.forPlugin(plugin.getId());
1416
+ async factory({ pluginMetadata, lifecycle }, databaseManager) {
1417
+ return databaseManager.forPlugin(pluginMetadata.getId(), {
1418
+ pluginMetadata,
1419
+ lifecycle
1420
+ });
1380
1421
  }
1381
1422
  });
1382
1423
 
1383
- const discoveryFactory = backendPluginApi.createServiceFactory({
1424
+ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
1384
1425
  service: backendPluginApi.coreServices.discovery,
1385
1426
  deps: {
1386
1427
  config: backendPluginApi.coreServices.config
@@ -1390,7 +1431,7 @@ const discoveryFactory = backendPluginApi.createServiceFactory({
1390
1431
  }
1391
1432
  });
1392
1433
 
1393
- const httpRouterFactory = backendPluginApi.createServiceFactory(
1434
+ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
1394
1435
  (options) => ({
1395
1436
  service: backendPluginApi.coreServices.httpRouter,
1396
1437
  deps: {
@@ -1410,7 +1451,7 @@ const httpRouterFactory = backendPluginApi.createServiceFactory(
1410
1451
  })
1411
1452
  );
1412
1453
 
1413
- const identityFactory = backendPluginApi.createServiceFactory(
1454
+ const identityServiceFactory = backendPluginApi.createServiceFactory(
1414
1455
  (options) => ({
1415
1456
  service: backendPluginApi.coreServices.identity,
1416
1457
  deps: {
@@ -1422,7 +1463,7 @@ const identityFactory = backendPluginApi.createServiceFactory(
1422
1463
  })
1423
1464
  );
1424
1465
 
1425
- const lifecycleFactory = backendPluginApi.createServiceFactory({
1466
+ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
1426
1467
  service: backendPluginApi.coreServices.lifecycle,
1427
1468
  deps: {
1428
1469
  logger: backendPluginApi.coreServices.logger,
@@ -1432,18 +1473,17 @@ const lifecycleFactory = backendPluginApi.createServiceFactory({
1432
1473
  async factory({ rootLifecycle, logger, pluginMetadata }) {
1433
1474
  const plugin = pluginMetadata.getId();
1434
1475
  return {
1435
- addShutdownHook(options) {
1476
+ addShutdownHook(hook, options) {
1436
1477
  var _a, _b;
1437
- rootLifecycle.addShutdownHook({
1438
- ...options,
1439
- logger: (_b = (_a = options.logger) == null ? void 0 : _a.child({ plugin })) != null ? _b : logger
1478
+ rootLifecycle.addShutdownHook(hook, {
1479
+ logger: (_b = (_a = options == null ? void 0 : options.logger) == null ? void 0 : _a.child({ plugin })) != null ? _b : logger
1440
1480
  });
1441
1481
  }
1442
1482
  };
1443
1483
  }
1444
1484
  });
1445
1485
 
1446
- const loggerFactory = backendPluginApi.createServiceFactory({
1486
+ const loggerServiceFactory = backendPluginApi.createServiceFactory({
1447
1487
  service: backendPluginApi.coreServices.logger,
1448
1488
  deps: {
1449
1489
  rootLogger: backendPluginApi.coreServices.rootLogger,
@@ -1454,7 +1494,7 @@ const loggerFactory = backendPluginApi.createServiceFactory({
1454
1494
  }
1455
1495
  });
1456
1496
 
1457
- const permissionsFactory = backendPluginApi.createServiceFactory({
1497
+ const permissionsServiceFactory = backendPluginApi.createServiceFactory({
1458
1498
  service: backendPluginApi.coreServices.permissions,
1459
1499
  deps: {
1460
1500
  config: backendPluginApi.coreServices.config,
@@ -1563,11 +1603,8 @@ findConflictingPath_fn = function(newPath) {
1563
1603
  return void 0;
1564
1604
  };
1565
1605
 
1566
- function defaultConfigure({
1567
- app,
1568
- routes,
1569
- middleware
1570
- }) {
1606
+ function defaultConfigure(context) {
1607
+ const { app, routes, middleware } = context;
1571
1608
  app.use(middleware.helmet());
1572
1609
  app.use(middleware.cors());
1573
1610
  app.use(middleware.compression());
@@ -1576,46 +1613,41 @@ function defaultConfigure({
1576
1613
  app.use(middleware.notFound());
1577
1614
  app.use(middleware.error());
1578
1615
  }
1579
- const rootHttpRouterFactory = backendPluginApi.createServiceFactory({
1580
- service: backendPluginApi.coreServices.rootHttpRouter,
1581
- deps: {
1582
- config: backendPluginApi.coreServices.config,
1583
- rootLogger: backendPluginApi.coreServices.rootLogger,
1584
- lifecycle: backendPluginApi.coreServices.rootLifecycle
1585
- },
1586
- async factory({ config, rootLogger, lifecycle }, {
1587
- indexPath,
1588
- configure = defaultConfigure
1589
- } = {}) {
1590
- const logger = rootLogger.child({ service: "rootHttpRouter" });
1591
- const app = express__default["default"]();
1592
- const router = DefaultRootHttpRouter.create({ indexPath });
1593
- const middleware = MiddlewareFactory.create({ config, logger });
1594
- configure({
1595
- app,
1596
- routes: router.handler(),
1597
- middleware,
1598
- config,
1599
- logger,
1600
- lifecycle
1601
- });
1602
- const server = await createHttpServer(
1603
- app,
1604
- readHttpServerOptions(config.getOptionalConfig("backend")),
1605
- { logger }
1606
- );
1607
- lifecycle.addShutdownHook({
1608
- async fn() {
1609
- await server.stop();
1610
- },
1611
- logger
1612
- });
1613
- await server.start();
1614
- return router;
1615
- }
1616
- });
1616
+ const rootHttpRouterServiceFactory = backendPluginApi.createServiceFactory(
1617
+ (options) => ({
1618
+ service: backendPluginApi.coreServices.rootHttpRouter,
1619
+ deps: {
1620
+ config: backendPluginApi.coreServices.config,
1621
+ rootLogger: backendPluginApi.coreServices.rootLogger,
1622
+ lifecycle: backendPluginApi.coreServices.rootLifecycle
1623
+ },
1624
+ async factory({ config, rootLogger, lifecycle }) {
1625
+ const { indexPath, configure = defaultConfigure } = options != null ? options : {};
1626
+ const logger = rootLogger.child({ service: "rootHttpRouter" });
1627
+ const app = express__default["default"]();
1628
+ const router = DefaultRootHttpRouter.create({ indexPath });
1629
+ const middleware = MiddlewareFactory.create({ config, logger });
1630
+ configure({
1631
+ app,
1632
+ routes: router.handler(),
1633
+ middleware,
1634
+ config,
1635
+ logger,
1636
+ lifecycle
1637
+ });
1638
+ const server = await createHttpServer(
1639
+ app,
1640
+ readHttpServerOptions(config.getOptionalConfig("backend")),
1641
+ { logger }
1642
+ );
1643
+ lifecycle.addShutdownHook(() => server.stop());
1644
+ await server.start();
1645
+ return router;
1646
+ }
1647
+ })
1648
+ );
1617
1649
 
1618
- const rootLoggerFactory = backendPluginApi.createServiceFactory({
1650
+ const rootLoggerServiceFactory = backendPluginApi.createServiceFactory({
1619
1651
  service: backendPluginApi.coreServices.rootLogger,
1620
1652
  deps: {
1621
1653
  config: backendPluginApi.coreServices.config
@@ -1637,7 +1669,7 @@ const rootLoggerFactory = backendPluginApi.createServiceFactory({
1637
1669
  }
1638
1670
  });
1639
1671
 
1640
- const schedulerFactory = backendPluginApi.createServiceFactory({
1672
+ const schedulerServiceFactory = backendPluginApi.createServiceFactory({
1641
1673
  service: backendPluginApi.coreServices.scheduler,
1642
1674
  deps: {
1643
1675
  plugin: backendPluginApi.coreServices.pluginMetadata,
@@ -1653,7 +1685,7 @@ const schedulerFactory = backendPluginApi.createServiceFactory({
1653
1685
  }
1654
1686
  });
1655
1687
 
1656
- const tokenManagerFactory = backendPluginApi.createServiceFactory({
1688
+ const tokenManagerServiceFactory = backendPluginApi.createServiceFactory({
1657
1689
  service: backendPluginApi.coreServices.tokenManager,
1658
1690
  deps: {
1659
1691
  config: backendPluginApi.coreServices.config,
@@ -1669,7 +1701,7 @@ const tokenManagerFactory = backendPluginApi.createServiceFactory({
1669
1701
  }
1670
1702
  });
1671
1703
 
1672
- const urlReaderFactory = backendPluginApi.createServiceFactory({
1704
+ const urlReaderServiceFactory = backendPluginApi.createServiceFactory({
1673
1705
  service: backendPluginApi.coreServices.urlReader,
1674
1706
  deps: {
1675
1707
  config: backendPluginApi.coreServices.config,
@@ -1686,26 +1718,26 @@ const urlReaderFactory = backendPluginApi.createServiceFactory({
1686
1718
  exports.DefaultRootHttpRouter = DefaultRootHttpRouter;
1687
1719
  exports.MiddlewareFactory = MiddlewareFactory;
1688
1720
  exports.WinstonLogger = WinstonLogger;
1689
- exports.cacheFactory = cacheFactory;
1690
- exports.configFactory = configFactory;
1721
+ exports.cacheServiceFactory = cacheServiceFactory;
1722
+ exports.configServiceFactory = configServiceFactory;
1691
1723
  exports.createConfigSecretEnumerator = createConfigSecretEnumerator;
1692
1724
  exports.createHttpServer = createHttpServer;
1693
1725
  exports.createSpecializedBackend = createSpecializedBackend;
1694
- exports.databaseFactory = databaseFactory;
1695
- exports.discoveryFactory = discoveryFactory;
1696
- exports.httpRouterFactory = httpRouterFactory;
1697
- exports.identityFactory = identityFactory;
1698
- exports.lifecycleFactory = lifecycleFactory;
1726
+ exports.databaseServiceFactory = databaseServiceFactory;
1727
+ exports.discoveryServiceFactory = discoveryServiceFactory;
1728
+ exports.httpRouterServiceFactory = httpRouterServiceFactory;
1729
+ exports.identityServiceFactory = identityServiceFactory;
1730
+ exports.lifecycleServiceFactory = lifecycleServiceFactory;
1699
1731
  exports.loadBackendConfig = loadBackendConfig;
1700
- exports.loggerFactory = loggerFactory;
1701
- exports.permissionsFactory = permissionsFactory;
1732
+ exports.loggerServiceFactory = loggerServiceFactory;
1733
+ exports.permissionsServiceFactory = permissionsServiceFactory;
1702
1734
  exports.readCorsOptions = readCorsOptions;
1703
1735
  exports.readHelmetOptions = readHelmetOptions;
1704
1736
  exports.readHttpServerOptions = readHttpServerOptions;
1705
- exports.rootHttpRouterFactory = rootHttpRouterFactory;
1706
- exports.rootLifecycleFactory = rootLifecycleFactory;
1707
- exports.rootLoggerFactory = rootLoggerFactory;
1708
- exports.schedulerFactory = schedulerFactory;
1709
- exports.tokenManagerFactory = tokenManagerFactory;
1710
- exports.urlReaderFactory = urlReaderFactory;
1737
+ exports.rootHttpRouterServiceFactory = rootHttpRouterServiceFactory;
1738
+ exports.rootLifecycleServiceFactory = rootLifecycleServiceFactory;
1739
+ exports.rootLoggerServiceFactory = rootLoggerServiceFactory;
1740
+ exports.schedulerServiceFactory = schedulerServiceFactory;
1741
+ exports.tokenManagerServiceFactory = tokenManagerServiceFactory;
1742
+ exports.urlReaderServiceFactory = urlReaderServiceFactory;
1711
1743
  //# sourceMappingURL=index.cjs.js.map