From e7cce2b60385a09a57caaaae1f355cc967a7b01e Mon Sep 17 00:00:00 2001 From: Phil Kuang Date: Fri, 3 Dec 2021 15:49:52 -0500 Subject: [PATCH] fix(techdocsStorageClient): properly construct baseUrls Signed-off-by: Phil Kuang --- .changeset/techdocs-forty-pumas-compete.md | 5 +++++ plugins/techdocs/src/client.test.ts | 6 ++++++ plugins/techdocs/src/client.ts | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/techdocs-forty-pumas-compete.md diff --git a/.changeset/techdocs-forty-pumas-compete.md b/.changeset/techdocs-forty-pumas-compete.md new file mode 100644 index 0000000000..929ce3e2c9 --- /dev/null +++ b/.changeset/techdocs-forty-pumas-compete.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Fix issue where assets weren't being fetched from the correct URL path for doc URLs without trailing slashes diff --git a/plugins/techdocs/src/client.test.ts b/plugins/techdocs/src/client.test.ts index 7624f250d9..c05d0cc324 100644 --- a/plugins/techdocs/src/client.test.ts +++ b/plugins/techdocs/src/client.test.ts @@ -59,6 +59,12 @@ describe('TechDocsStorageClient', () => { ).resolves.toEqual( `${mockBaseUrl}/static/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test.js`, ); + + await expect( + storageApi.getBaseUrl('../test.js', mockEntity, 'some-docs-path'), + ).resolves.toEqual( + `${mockBaseUrl}/static/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test.js`, + ); }); it('should return base url with correct entity structure', async () => { diff --git a/plugins/techdocs/src/client.ts b/plugins/techdocs/src/client.ts index 8a3ad59c03..f965cd7ced 100644 --- a/plugins/techdocs/src/client.ts +++ b/plugins/techdocs/src/client.ts @@ -263,9 +263,11 @@ export class TechDocsStorageClient implements TechDocsStorageApi { const { kind, namespace, name } = entityId; const apiOrigin = await this.getApiOrigin(); + const newBaseUrl = `${apiOrigin}/static/docs/${namespace}/${kind}/${name}/${path}`; + return new URL( oldBaseUrl, - `${apiOrigin}/static/docs/${namespace}/${kind}/${name}/${path}`, + newBaseUrl.endsWith('/') ? newBaseUrl : `${newBaseUrl}/`, ).toString(); } }