fix: Include bucketRootPath in AWS publisher for Techdocs

Signed-off-by: aarontsharp <aaron.sharp@carta.com>
This commit is contained in:
aarontsharp
2022-08-29 15:48:56 -07:00
parent 6f70113b57
commit 33ac0c0546
3 changed files with 12 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-node': patch
---
Fix Techdocs S3 publisher to include bucketRootPath in requests. Currently, requests made to S3 are omitting this path and fail with a 404
@@ -537,13 +537,13 @@ describe('AwsS3Publish', () => {
app = express().use(publisher.docsRouter());
const pngResponse = await request(app).get(
`/${rootPath}/${entityTripletPath}/img/with%20spaces.png`,
`/${entityTripletPath}/img/with%20spaces.png`,
);
expect(Buffer.from(pngResponse.body).toString('utf8')).toEqual(
'found it',
);
const jsResponse = await request(app).get(
`/${rootPath}/${entityTripletPath}/some%20folder/also%20with%20spaces.js`,
`/${entityTripletPath}/some%20folder/also%20with%20spaces.js`,
);
expect(jsResponse.text).toEqual('found it too');
});
@@ -558,13 +558,13 @@ describe('AwsS3Publish', () => {
app = express().use(publisher.docsRouter());
const pngResponse = await request(app).get(
`/${rootPath}/${entityTripletPath}/img/with%20spaces.png`,
`/${entityTripletPath}/img/with%20spaces.png`,
);
expect(Buffer.from(pngResponse.body).toString('utf8')).toEqual(
'found it',
);
const jsResponse = await request(app).get(
`/${rootPath}/${entityTripletPath}/some%20folder/also%20with%20spaces.js`,
`/${entityTripletPath}/some%20folder/also%20with%20spaces.js`,
);
expect(jsResponse.text).toEqual('found it too');
});
@@ -370,19 +370,14 @@ export class AwsS3Publish implements PublisherBase {
*/
docsRouter(): express.Handler {
return async (req, res) => {
// Decode and trim the leading forward slash
const decodedUri = decodeURI(req.path.replace(/^\//, ''));
// Root path is removed from the Uri so that legacy casing can be applied
// to the entity triplet without manipulating the root path
const decodedUriNoRoot = path.relative(this.bucketRootPath, decodedUri);
// filePath example - /default/component/documented-component/index.html
const filePathNoRoot = this.legacyPathCasing
? decodedUriNoRoot
: lowerCaseEntityTripletInStoragePath(decodedUriNoRoot);
? decodedUri
: lowerCaseEntityTripletInStoragePath(decodedUri);
// Re-prepend the root path to the relative file path
// Prepend the root path to the relative file path
const filePath = path.posix.join(this.bucketRootPath, filePathNoRoot);
// Files with different extensions (CSS, HTML) need to be served with different headers