Now I can help those who are faced with the same difficulty I faced.
If you are developing a new front-end plugin, for example, you will need to create a configSchema.d.ts
file in which you indicate the settings/variables it needs to access:
export interface Config {
exampleConfig: {
/**
* Base URL Example Service
* @visibility frontend
*/
baseUrl?: string;
/**
* Params at url in Example Service
* @visibility frontend
*/
getParamsUrl?: string;
/**
* Number of results that must be obtained
* @visibility frontend
*/
resultLimit?: number;
/**
* URL for PUT method
* @visibility frontend
*/
putUrl?: string;
/**
* Params for PUT method
* @visibility frontend
*/
putParamsUrl?: string;
/**
* Token Example Service
* @visibility frontend
*/
token?: string;
};
In the file responsible for creating the API, for example, you import ConfigApi
from the @backstage/core-plugin-api
package.
Below is an example of how variables/configurations could be accessed:
import { ConfigApi } from "@backstage/core-plugin-api";
[...]
export class ExampleClient implements ExampleApi {
private readonly backendBaseUrl: string;
private readonly baseUrl: string;
private readonly getParamsUrl: string;
private readonly queryResult: number;
private readonly putUrl: string;
private readonly putParamsUrl: string;
private readonly token: string;
private readonly managementAPi: ManagementRDMClient
constructor(options: { configApi: ConfigApi; fetchApi: FetchApi }
) {
this.backendBaseUrl = options.configApi.getString('backend.baseUrl');
this.baseUrl = options.configApi.getString('exampleConfig.baseUrl');
this.getParamsUrl = options.configApi.getString('exampleConfig.getParamsUrl');
this.queryResult = options.configApi.getNumber('exampleConfig.resultLimit');
this.putUrl = options.configApi.getString('exampleConfig.putUrl');
this.putParamsUrl = options.configApi.getString('exampleConfig.putParamsUrl');
this.token = options.configApi.getString('exampleConfig.token');
}
[...]
}