Merge pull request #3320 from backstage/orkohunter/use-config-for-backend-base-url
This commit is contained in:
@@ -50,7 +50,7 @@ export default async function createPlugin({
|
||||
const urlPreparer = new UrlPreparer(reader, logger);
|
||||
preparers.register('url', urlPreparer);
|
||||
|
||||
const publisher = new LocalPublish(logger);
|
||||
const publisher = new LocalPublish(logger, discovery);
|
||||
|
||||
const dockerClient = new Docker();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export default async function createPlugin({
|
||||
preparers.register('github', commonGitPreparer);
|
||||
preparers.register('gitlab', commonGitPreparer);
|
||||
|
||||
const publisher = new LocalPublish(logger);
|
||||
const publisher = new LocalPublish(logger, discovery);
|
||||
|
||||
const dockerClient = new Docker();
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export async function startStandaloneServer(
|
||||
const techdocsGenerator = new TechdocsGenerator(logger, config);
|
||||
generators.register('techdocs', techdocsGenerator);
|
||||
|
||||
const publisher = new LocalPublish(logger);
|
||||
const publisher = new LocalPublish(logger, discovery);
|
||||
|
||||
const dockerClient = new Docker();
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
getVoidLogger,
|
||||
PluginEndpointDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
import { LocalPublish } from './local';
|
||||
|
||||
const createMockEntity = (annotations = {}) => {
|
||||
@@ -37,7 +40,12 @@ const logger = getVoidLogger();
|
||||
|
||||
describe('local publisher', () => {
|
||||
it('should publish generated documentation dir', async () => {
|
||||
const publisher = new LocalPublish(logger);
|
||||
const testDiscovery: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
getBaseUrl: jest.fn().mockResolvedValueOnce('http://localhost:7000'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
|
||||
const publisher = new LocalPublish(logger, testDiscovery);
|
||||
|
||||
const mockEntity = createMockEntity();
|
||||
|
||||
|
||||
@@ -17,13 +17,18 @@ import fs from 'fs-extra';
|
||||
import { Logger } from 'winston';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { PublisherBase } from './types';
|
||||
import { resolvePackagePath } from '@backstage/backend-common';
|
||||
import {
|
||||
resolvePackagePath,
|
||||
PluginEndpointDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
|
||||
export class LocalPublish implements PublisherBase {
|
||||
private readonly logger: Logger;
|
||||
private readonly discovery: PluginEndpointDiscovery;
|
||||
|
||||
constructor(logger: Logger) {
|
||||
constructor(logger: Logger, discovery: PluginEndpointDiscovery) {
|
||||
this.logger = logger;
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
publish({
|
||||
@@ -63,9 +68,16 @@ export class LocalPublish implements PublisherBase {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
resolve({
|
||||
remoteUrl: `http://localhost:7000/api/techdocs/static/docs/${entity.metadata.name}`,
|
||||
});
|
||||
this.discovery
|
||||
.getBaseUrl('techdocs')
|
||||
.then(techdocsApiUrl => {
|
||||
resolve({
|
||||
remoteUrl: `${techdocsApiUrl}/static/docs/${entity.metadata.name}`,
|
||||
});
|
||||
})
|
||||
.catch(reason => {
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user