core-app-api: defaultConfigLoader no longer requires APP_CONFIG to be set
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/core-app-api': patch
|
||||
'@backstage/frontend-defaults': patch
|
||||
---
|
||||
|
||||
The default config loader no longer requires `process.env.APP_CONFIG` to be set, allowing config to be read from other sources instead.
|
||||
@@ -29,6 +29,10 @@ describe('defaultConfigLoaderSync', () => {
|
||||
delete anyWindow.__APP_CONFIG__;
|
||||
});
|
||||
|
||||
it('loads nothing is config is missing', () => {
|
||||
expect(defaultConfigLoaderSync()).toEqual([]);
|
||||
});
|
||||
|
||||
it('loads static config', () => {
|
||||
anyEnv.APP_CONFIG = [
|
||||
{ data: { my: 'config' }, context: 'a' },
|
||||
@@ -95,12 +99,6 @@ describe('defaultConfigLoaderSync', () => {
|
||||
expect(ConfigReader.fromConfigs(configs).get('my')).toBe('override-config');
|
||||
});
|
||||
|
||||
it('fails to load invalid missing config', () => {
|
||||
expect(() => defaultConfigLoaderSync()).toThrow(
|
||||
'No static configuration provided',
|
||||
);
|
||||
});
|
||||
|
||||
it('fails to load invalid static config', () => {
|
||||
anyEnv.APP_CONFIG = { my: 'invalid-config' };
|
||||
expect(() => defaultConfigLoaderSync()).toThrow(
|
||||
|
||||
@@ -40,14 +40,15 @@ export function defaultConfigLoaderSync(
|
||||
// It's a param so we can test it, but at runtime this will always fall back to default.
|
||||
runtimeConfigJson: string = '__APP_INJECTED_RUNTIME_CONFIG__',
|
||||
) {
|
||||
const appConfig = process.env.APP_CONFIG;
|
||||
if (!appConfig) {
|
||||
throw new Error('No static configuration provided');
|
||||
const configs = new Array<AppConfig>();
|
||||
|
||||
const staticConfig = process.env.APP_CONFIG;
|
||||
if (staticConfig) {
|
||||
if (!Array.isArray(staticConfig)) {
|
||||
throw new Error('Static configuration has invalid format');
|
||||
}
|
||||
configs.push(...staticConfig);
|
||||
}
|
||||
if (!Array.isArray(appConfig)) {
|
||||
throw new Error('Static configuration has invalid format');
|
||||
}
|
||||
const configs = appConfig.slice() as unknown as AppConfig[];
|
||||
|
||||
// Check if we have any config script tags, otherwise fall back to injected config
|
||||
const configScripts = document.querySelectorAll(
|
||||
|
||||
Reference in New Issue
Block a user