Merge pull request #21632 from davidfestal/support-additional-config-schemas
Support external config schemas in the backend
This commit is contained in:
@@ -3,9 +3,23 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { ConfigSchema } from '@backstage/config-loader';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { Handler } from 'express';
|
||||
|
||||
// @public
|
||||
export interface ConfigSchemaExtensionPoint {
|
||||
setConfigSchema(configSchema: ConfigSchema): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
export const configSchemaExtensionPoint: ExtensionPoint<ConfigSchemaExtensionPoint>;
|
||||
|
||||
// @public
|
||||
export function loadCompiledConfigSchema(
|
||||
appDistDir: string,
|
||||
): Promise<ConfigSchema | undefined>;
|
||||
|
||||
// @public
|
||||
export interface StaticFallbackHandlerExtensionPoint {
|
||||
setStaticFallbackHandler(handler: Handler): void;
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/config-loader": "workspace:^",
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1"
|
||||
"express": "^4.17.1",
|
||||
"fs-extra": "10.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { ConfigSchema } from '@backstage/config-loader';
|
||||
import { Handler } from 'express';
|
||||
|
||||
/**
|
||||
@@ -50,3 +51,25 @@ export const staticFallbackHandlerExtensionPoint =
|
||||
createExtensionPoint<StaticFallbackHandlerExtensionPoint>({
|
||||
id: 'app.staticFallbackHandler',
|
||||
});
|
||||
|
||||
/**
|
||||
* The interface for {@link configSchemaExtensionPoint}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ConfigSchemaExtensionPoint {
|
||||
/**
|
||||
* Sets the config schema. This can only be done once.
|
||||
*/
|
||||
setConfigSchema(configSchema: ConfigSchema): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension point the exposes the ability to override the config schema used by the frontend application.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const configSchemaExtensionPoint =
|
||||
createExtensionPoint<ConfigSchemaExtensionPoint>({
|
||||
id: 'app.configSchema',
|
||||
});
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
export {
|
||||
staticFallbackHandlerExtensionPoint,
|
||||
type StaticFallbackHandlerExtensionPoint,
|
||||
configSchemaExtensionPoint,
|
||||
type ConfigSchemaExtensionPoint,
|
||||
} from './extensions';
|
||||
|
||||
export { loadCompiledConfigSchema } from './schema';
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { ConfigSchema, loadConfigSchema } from '@backstage/config-loader';
|
||||
|
||||
/**
|
||||
* Loads the config schema that is embedded in the frontend build.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export async function loadCompiledConfigSchema(
|
||||
appDistDir: string,
|
||||
): Promise<ConfigSchema | undefined> {
|
||||
const schemaPath = resolvePath(appDistDir, '.config-schema.json');
|
||||
if (await fs.pathExists(schemaPath)) {
|
||||
const serializedSchema = await fs.readJson(schemaPath);
|
||||
|
||||
return await loadConfigSchema({
|
||||
serialized: serializedSchema,
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user