fix(techdocsStorageClient): properly construct baseUrls

Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
Phil Kuang
2021-12-03 15:49:52 -05:00
parent 7e726a10e9
commit e7cce2b603
3 changed files with 14 additions and 1 deletions
@@ -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
+6
View File
@@ -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 () => {
+3 -1
View File
@@ -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();
}
}