refactor: Use {{pluginId}} pattern and update docs
Signed-off-by: Jack Palmer <jackpalmer@spotify.com>
This commit is contained in:
Vendored
+1
-1
@@ -217,7 +217,7 @@ export interface Config {
|
||||
* The target baseUrl to use for the plugin
|
||||
*
|
||||
* Can be either a string or an object with internal and external keys.
|
||||
* Targets with `{pluginId}` in the url will be replaced with the pluginId.
|
||||
* Targets with `{{pluginId}}` or `{{ pluginId }} in the url will be replaced with the pluginId.
|
||||
*/
|
||||
target: string | { internal: string; external: string };
|
||||
/** Array of plugins which use the target baseUrl. */
|
||||
|
||||
@@ -163,7 +163,7 @@ describe('HostDiscovery', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('replaces {pluginId} in the target', async () => {
|
||||
it('replaces {{pluginId}} or {{ pluginId }} in the target', async () => {
|
||||
const discovery = HostDiscovery.fromConfig(
|
||||
new ConfigReader({
|
||||
backend: {
|
||||
@@ -173,13 +173,13 @@ describe('HostDiscovery', () => {
|
||||
discovery: {
|
||||
endpoints: [
|
||||
{
|
||||
target: 'http://common-backend:8080/api/{pluginId}',
|
||||
target: 'http://common-backend:8080/api/{{pluginId}}',
|
||||
plugins: ['catalog', 'docs'],
|
||||
},
|
||||
{
|
||||
target: {
|
||||
internal: 'http://scaffolder-internal:8080/api/{pluginId}',
|
||||
external: 'http://scaffolder-external:8080/api/{pluginId}',
|
||||
internal: 'http://scaffolder-internal:8080/api/{{ pluginId }}',
|
||||
external: 'http://scaffolder-external:8080/api/{{ pluginId }}',
|
||||
},
|
||||
plugins: ['scaffolder'],
|
||||
},
|
||||
|
||||
@@ -37,7 +37,20 @@ export class HostDiscovery implements PluginEndpointDiscovery {
|
||||
* discovering the external URL, and the `.listen` and `.https` config
|
||||
* for the internal one.
|
||||
*
|
||||
* Can be overridden by in config by providing a `discovery` section with a `<pluginId>` key.
|
||||
* Can be overridden by in config by providing a target and corresponding plugin in `discovery.endpoint`.
|
||||
* eg.
|
||||
* ```yaml
|
||||
* discovery:
|
||||
* endpoints:
|
||||
* - target: https://internal.example.com/internal-catalog
|
||||
* plugins: [catalog]
|
||||
* - target: https://internal.example.com/secure/api/{{pluginId}}
|
||||
* plugins: [auth, permissions]
|
||||
* - target:
|
||||
* internal: https://internal.example.com/search
|
||||
* external: https://example.com/search
|
||||
* plugins: [search]
|
||||
* ```
|
||||
*
|
||||
* The basePath defaults to `/api`, meaning the default full internal
|
||||
* path for the `catalog` plugin will be `http://localhost:7007/api/catalog`.
|
||||
@@ -92,10 +105,10 @@ export class HostDiscovery implements PluginEndpointDiscovery {
|
||||
}
|
||||
|
||||
if (typeof target === 'string') {
|
||||
return target.replace('{pluginId}', pluginId);
|
||||
return target.replace(/\{\{\s*pluginId\s*\}\}/, pluginId);
|
||||
}
|
||||
|
||||
return target[type].replace('{pluginId}', pluginId);
|
||||
return target[type].replace(/\{\{\s*pluginId\s*\}\}/, pluginId);
|
||||
}
|
||||
|
||||
async getBaseUrl(pluginId: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user