@backstage/backend-app-api 0.5.5 → 0.5.6-next.2

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/CHANGELOG.md CHANGED
@@ -1,28 +1,57 @@
1
1
  # @backstage/backend-app-api
2
2
 
3
- ## 0.5.5
3
+ ## 0.5.6-next.2
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - 74491c9602: Moved `HostDiscovery` from `@backstage/backend-common`.
8
+ - a4617c422a: Added `watch` option to configuration loaders that can be used to disable file watching by setting it to `false`.
7
9
  - Updated dependencies
8
- - @backstage/plugin-auth-node@0.3.2
9
- - @backstage/backend-plugin-api@0.6.5
10
- - @backstage/plugin-permission-node@0.7.16
11
- - @backstage/backend-common@0.19.7
12
- - @backstage/backend-tasks@0.5.10
13
- - @backstage/config-loader@1.5.0
10
+ - @backstage/backend-common@0.19.8-next.2
11
+ - @backstage/plugin-auth-node@0.4.0-next.2
12
+ - @backstage/config-loader@1.5.1-next.1
13
+ - @backstage/errors@1.2.3-next.0
14
+ - @backstage/backend-tasks@0.5.11-next.2
15
+ - @backstage/plugin-permission-node@0.7.17-next.2
16
+ - @backstage/backend-plugin-api@0.6.6-next.2
17
+ - @backstage/cli-common@0.1.13-next.0
18
+ - @backstage/cli-node@0.1.5-next.1
19
+ - @backstage/config@1.1.1-next.0
20
+ - @backstage/types@1.1.1
14
21
 
15
- ## 0.5.4
22
+ ## 0.5.5-next.1
16
23
 
17
24
  ### Patch Changes
18
25
 
19
26
  - Updated dependencies
20
- - @backstage/plugin-auth-node@0.3.1
21
- - @backstage/backend-plugin-api@0.6.4
22
- - @backstage/plugin-permission-node@0.7.15
23
- - @backstage/backend-common@0.19.6
24
- - @backstage/backend-tasks@0.5.9
25
- - @backstage/config-loader@1.5.0
27
+ - @backstage/backend-tasks@0.5.10-next.1
28
+ - @backstage/backend-common@0.19.7-next.1
29
+ - @backstage/backend-plugin-api@0.6.5-next.1
30
+ - @backstage/plugin-auth-node@0.3.2-next.1
31
+ - @backstage/plugin-permission-node@0.7.16-next.1
32
+ - @backstage/config@1.1.0
33
+ - @backstage/cli-common@0.1.13-next.0
34
+ - @backstage/cli-node@0.1.5-next.0
35
+ - @backstage/config-loader@1.5.1-next.0
36
+ - @backstage/errors@1.2.2
37
+ - @backstage/types@1.1.1
38
+
39
+ ## 0.5.5-next.0
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies
44
+ - @backstage/plugin-auth-node@0.3.2-next.0
45
+ - @backstage/config-loader@1.5.1-next.0
46
+ - @backstage/cli-common@0.1.13-next.0
47
+ - @backstage/backend-common@0.19.7-next.0
48
+ - @backstage/config@1.1.0
49
+ - @backstage/backend-plugin-api@0.6.5-next.0
50
+ - @backstage/backend-tasks@0.5.10-next.0
51
+ - @backstage/cli-node@0.1.5-next.0
52
+ - @backstage/errors@1.2.2
53
+ - @backstage/types@1.1.1
54
+ - @backstage/plugin-permission-node@0.7.16-next.0
26
55
 
27
56
  ## 0.5.3
28
57
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-app-api",
3
- "version": "0.5.5",
3
+ "version": "0.5.6-next.2",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/config.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2020 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface Config {
18
+ /** Discovery options. */
19
+ discovery?: {
20
+ /**
21
+ * Endpoints
22
+ *
23
+ * A list of target baseUrls and the associated plugins.
24
+ */
25
+ endpoints: {
26
+ /**
27
+ * The target baseUrl to use for the plugin
28
+ *
29
+ * Can be either a string or an object with internal and external keys.
30
+ * Targets with `{{pluginId}}` or `{{ pluginId }} in the url will be replaced with the pluginId.
31
+ */
32
+ target: string | { internal: string; external: string };
33
+ /** Array of plugins which use the target baseUrl. */
34
+ plugins: string[];
35
+ }[];
36
+ };
37
+ }
package/dist/index.cjs.js CHANGED
@@ -23,6 +23,7 @@ var winston = require('winston');
23
23
  var backendPluginApi = require('@backstage/backend-plugin-api');
24
24
  var alpha = require('@backstage/backend-plugin-api/alpha');
25
25
  var backendCommon = require('@backstage/backend-common');
26
+ var backendAppApi = require('@backstage/backend-app-api');
26
27
  var PromiseRouter = require('express-promise-router');
27
28
  var types = require('@backstage/types');
28
29
  var pluginAuthNode = require('@backstage/plugin-auth-node');
@@ -216,7 +217,7 @@ async function createConfigSecretEnumerator(options) {
216
217
  };
217
218
  }
218
219
  async function loadBackendConfig(options) {
219
- var _a;
220
+ var _a, _b;
220
221
  const args = parseArgs__default["default"](options.argv);
221
222
  const configTargets = [(_a = args.config) != null ? _a : []].flat().map((arg) => isValidUrl(arg) ? { url: arg } : { path: path.resolve(arg) });
222
223
  const paths = cliCommon.findPaths(__dirname);
@@ -226,7 +227,7 @@ async function loadBackendConfig(options) {
226
227
  configRoot: paths.targetRoot,
227
228
  configTargets,
228
229
  remote: options.remote,
229
- watch: {
230
+ watch: ((_b = options.watch) != null ? _b : true) ? {
230
231
  onChange(newConfigs) {
231
232
  console.info(
232
233
  `Reloaded config from ${newConfigs.map((c) => c.context).join(", ")}`
@@ -246,7 +247,7 @@ async function loadBackendConfig(options) {
246
247
  module.hot.addDisposeHandler(resolve);
247
248
  }
248
249
  })
249
- }
250
+ } : void 0
250
251
  });
251
252
  console.info(
252
253
  `Loaded config from ${appConfigs.map((c) => c.context).join(", ")}`
@@ -1941,13 +1942,94 @@ const databaseServiceFactory = backendPluginApi.createServiceFactory({
1941
1942
  }
1942
1943
  });
1943
1944
 
1945
+ class HostDiscovery {
1946
+ constructor(internalBaseUrl, externalBaseUrl, discoveryConfig) {
1947
+ this.internalBaseUrl = internalBaseUrl;
1948
+ this.externalBaseUrl = externalBaseUrl;
1949
+ this.discoveryConfig = discoveryConfig;
1950
+ }
1951
+ /**
1952
+ * Creates a new HostDiscovery discovery instance by reading
1953
+ * from the `backend` config section, specifically the `.baseUrl` for
1954
+ * discovering the external URL, and the `.listen` and `.https` config
1955
+ * for the internal one.
1956
+ *
1957
+ * Can be overridden in config by providing a target and corresponding plugins in `discovery.endpoints`.
1958
+ * eg.
1959
+ * ```yaml
1960
+ * discovery:
1961
+ * endpoints:
1962
+ * - target: https://internal.example.com/internal-catalog
1963
+ * plugins: [catalog]
1964
+ * - target: https://internal.example.com/secure/api/{{pluginId}}
1965
+ * plugins: [auth, permission]
1966
+ * - target:
1967
+ * internal: https://internal.example.com/search
1968
+ * external: https://example.com/search
1969
+ * plugins: [search]
1970
+ * ```
1971
+ *
1972
+ * The basePath defaults to `/api`, meaning the default full internal
1973
+ * path for the `catalog` plugin will be `http://localhost:7007/api/catalog`.
1974
+ */
1975
+ static fromConfig(config, options) {
1976
+ var _a;
1977
+ const basePath = (_a = options == null ? void 0 : options.basePath) != null ? _a : "/api";
1978
+ const externalBaseUrl = config.getString("backend.baseUrl").replace(/\/+$/, "");
1979
+ const {
1980
+ listen: { host: listenHost = "::", port: listenPort }
1981
+ } = backendAppApi.readHttpServerOptions(config.getConfig("backend"));
1982
+ const protocol = config.has("backend.https") ? "https" : "http";
1983
+ let host = listenHost;
1984
+ if (host === "::" || host === "") {
1985
+ host = "localhost";
1986
+ } else if (host === "0.0.0.0") {
1987
+ host = "127.0.0.1";
1988
+ }
1989
+ if (host.includes(":")) {
1990
+ host = `[${host}]`;
1991
+ }
1992
+ const internalBaseUrl = `${protocol}://${host}:${listenPort}`;
1993
+ return new HostDiscovery(
1994
+ internalBaseUrl + basePath,
1995
+ externalBaseUrl + basePath,
1996
+ config.getOptionalConfig("discovery")
1997
+ );
1998
+ }
1999
+ getTargetFromConfig(pluginId, type) {
2000
+ var _a, _b;
2001
+ const endpoints = (_a = this.discoveryConfig) == null ? void 0 : _a.getOptionalConfigArray("endpoints");
2002
+ const target = (_b = endpoints == null ? void 0 : endpoints.find((endpoint) => endpoint.getStringArray("plugins").includes(pluginId))) == null ? void 0 : _b.get("target");
2003
+ if (!target) {
2004
+ const baseUrl = type === "external" ? this.externalBaseUrl : this.internalBaseUrl;
2005
+ return `${baseUrl}/${encodeURIComponent(pluginId)}`;
2006
+ }
2007
+ if (typeof target === "string") {
2008
+ return target.replace(
2009
+ /\{\{\s*pluginId\s*\}\}/g,
2010
+ encodeURIComponent(pluginId)
2011
+ );
2012
+ }
2013
+ return target[type].replace(
2014
+ /\{\{\s*pluginId\s*\}\}/g,
2015
+ encodeURIComponent(pluginId)
2016
+ );
2017
+ }
2018
+ async getBaseUrl(pluginId) {
2019
+ return this.getTargetFromConfig(pluginId, "internal");
2020
+ }
2021
+ async getExternalBaseUrl(pluginId) {
2022
+ return this.getTargetFromConfig(pluginId, "external");
2023
+ }
2024
+ }
2025
+
1944
2026
  const discoveryServiceFactory = backendPluginApi.createServiceFactory({
1945
2027
  service: backendPluginApi.coreServices.discovery,
1946
2028
  deps: {
1947
2029
  config: backendPluginApi.coreServices.rootConfig
1948
2030
  },
1949
2031
  async factory({ config }) {
1950
- return backendCommon.HostDiscovery.fromConfig(config);
2032
+ return HostDiscovery.fromConfig(config);
1951
2033
  }
1952
2034
  });
1953
2035
 
@@ -2264,6 +2346,7 @@ const urlReaderServiceFactory = backendPluginApi.createServiceFactory({
2264
2346
  });
2265
2347
 
2266
2348
  exports.DefaultRootHttpRouter = DefaultRootHttpRouter;
2349
+ exports.HostDiscovery = HostDiscovery;
2267
2350
  exports.MiddlewareFactory = MiddlewareFactory;
2268
2351
  exports.WinstonLogger = WinstonLogger;
2269
2352
  exports.cacheServiceFactory = cacheServiceFactory;