@backstage/backend-app-api 0.5.5 → 0.5.6
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 +62 -14
- package/alpha/package.json +1 -1
- package/config.d.ts +37 -0
- package/dist/index.cjs.js +87 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +51 -3
- package/package.json +15 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,76 @@
|
|
|
1
1
|
# @backstage/backend-app-api
|
|
2
2
|
|
|
3
|
-
## 0.5.
|
|
3
|
+
## 0.5.6
|
|
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/
|
|
9
|
-
- @backstage/backend-
|
|
10
|
-
- @backstage/plugin-
|
|
11
|
-
- @backstage/
|
|
12
|
-
- @backstage/
|
|
13
|
-
- @backstage/
|
|
10
|
+
- @backstage/backend-tasks@0.5.11
|
|
11
|
+
- @backstage/backend-common@0.19.8
|
|
12
|
+
- @backstage/plugin-auth-node@0.4.0
|
|
13
|
+
- @backstage/config-loader@1.5.1
|
|
14
|
+
- @backstage/errors@1.2.3
|
|
15
|
+
- @backstage/cli-common@0.1.13
|
|
16
|
+
- @backstage/backend-plugin-api@0.6.6
|
|
17
|
+
- @backstage/plugin-permission-node@0.7.17
|
|
18
|
+
- @backstage/cli-node@0.1.5
|
|
19
|
+
- @backstage/config@1.1.1
|
|
20
|
+
- @backstage/types@1.1.1
|
|
14
21
|
|
|
15
|
-
## 0.5.
|
|
22
|
+
## 0.5.6-next.2
|
|
16
23
|
|
|
17
24
|
### Patch Changes
|
|
18
25
|
|
|
26
|
+
- 74491c9602: Moved `HostDiscovery` from `@backstage/backend-common`.
|
|
27
|
+
- a4617c422a: Added `watch` option to configuration loaders that can be used to disable file watching by setting it to `false`.
|
|
19
28
|
- Updated dependencies
|
|
20
|
-
- @backstage/
|
|
21
|
-
- @backstage/
|
|
22
|
-
- @backstage/
|
|
23
|
-
- @backstage/
|
|
24
|
-
- @backstage/backend-tasks@0.5.
|
|
25
|
-
- @backstage/
|
|
29
|
+
- @backstage/backend-common@0.19.8-next.2
|
|
30
|
+
- @backstage/plugin-auth-node@0.4.0-next.2
|
|
31
|
+
- @backstage/config-loader@1.5.1-next.1
|
|
32
|
+
- @backstage/errors@1.2.3-next.0
|
|
33
|
+
- @backstage/backend-tasks@0.5.11-next.2
|
|
34
|
+
- @backstage/plugin-permission-node@0.7.17-next.2
|
|
35
|
+
- @backstage/backend-plugin-api@0.6.6-next.2
|
|
36
|
+
- @backstage/cli-common@0.1.13-next.0
|
|
37
|
+
- @backstage/cli-node@0.1.5-next.1
|
|
38
|
+
- @backstage/config@1.1.1-next.0
|
|
39
|
+
- @backstage/types@1.1.1
|
|
40
|
+
|
|
41
|
+
## 0.5.5-next.1
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies
|
|
46
|
+
- @backstage/backend-tasks@0.5.10-next.1
|
|
47
|
+
- @backstage/backend-common@0.19.7-next.1
|
|
48
|
+
- @backstage/backend-plugin-api@0.6.5-next.1
|
|
49
|
+
- @backstage/plugin-auth-node@0.3.2-next.1
|
|
50
|
+
- @backstage/plugin-permission-node@0.7.16-next.1
|
|
51
|
+
- @backstage/config@1.1.0
|
|
52
|
+
- @backstage/cli-common@0.1.13-next.0
|
|
53
|
+
- @backstage/cli-node@0.1.5-next.0
|
|
54
|
+
- @backstage/config-loader@1.5.1-next.0
|
|
55
|
+
- @backstage/errors@1.2.2
|
|
56
|
+
- @backstage/types@1.1.1
|
|
57
|
+
|
|
58
|
+
## 0.5.5-next.0
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies
|
|
63
|
+
- @backstage/plugin-auth-node@0.3.2-next.0
|
|
64
|
+
- @backstage/config-loader@1.5.1-next.0
|
|
65
|
+
- @backstage/cli-common@0.1.13-next.0
|
|
66
|
+
- @backstage/backend-common@0.19.7-next.0
|
|
67
|
+
- @backstage/config@1.1.0
|
|
68
|
+
- @backstage/backend-plugin-api@0.6.5-next.0
|
|
69
|
+
- @backstage/backend-tasks@0.5.10-next.0
|
|
70
|
+
- @backstage/cli-node@0.1.5-next.0
|
|
71
|
+
- @backstage/errors@1.2.2
|
|
72
|
+
- @backstage/types@1.1.1
|
|
73
|
+
- @backstage/plugin-permission-node@0.7.16-next.0
|
|
26
74
|
|
|
27
75
|
## 0.5.3
|
|
28
76
|
|
package/alpha/package.json
CHANGED
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
|
|
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;
|