Merge pull request #8365 from kuangp/fix/techdocs

fix(techdocsStorageClient): properly construct baseUrls
This commit is contained in:
Camila Belo
2021-12-13 22:46:36 +01:00
committed by GitHub
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
@@ -62,6 +62,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();
}
}