From 33ac0c054621f1256499dd0d43f58010f5837f74 Mon Sep 17 00:00:00 2001 From: aarontsharp Date: Mon, 29 Aug 2022 15:48:56 -0700 Subject: [PATCH 1/3] fix: Include bucketRootPath in AWS publisher for Techdocs Signed-off-by: aarontsharp --- .changeset/big-spies-check.md | 5 +++++ .../techdocs-node/src/stages/publish/awsS3.test.ts | 8 ++++---- plugins/techdocs-node/src/stages/publish/awsS3.ts | 11 +++-------- 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 .changeset/big-spies-check.md diff --git a/.changeset/big-spies-check.md b/.changeset/big-spies-check.md new file mode 100644 index 0000000000..6f8c3208ee --- /dev/null +++ b/.changeset/big-spies-check.md @@ -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 diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts index 1ca9cf2abf..52d654d159 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts @@ -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'); }); diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.ts b/plugins/techdocs-node/src/stages/publish/awsS3.ts index 12940e0117..67a4157a5b 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.ts @@ -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 From 34db2893714c19892b0d5bcbffce74edce8a2a72 Mon Sep 17 00:00:00 2001 From: aarontsharp Date: Tue, 30 Aug 2022 08:47:21 -0700 Subject: [PATCH 2/3] Fix GCS also Signed-off-by: aarontsharp --- .../src/stages/publish/googleStorage.test.ts | 8 ++++---- .../src/stages/publish/googleStorage.ts | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/techdocs-node/src/stages/publish/googleStorage.test.ts b/plugins/techdocs-node/src/stages/publish/googleStorage.test.ts index b347f185c6..896e528644 100644 --- a/plugins/techdocs-node/src/stages/publish/googleStorage.test.ts +++ b/plugins/techdocs-node/src/stages/publish/googleStorage.test.ts @@ -527,13 +527,13 @@ describe('GoogleGCSPublish', () => { 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'); }); @@ -548,13 +548,13 @@ describe('GoogleGCSPublish', () => { 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'); }); diff --git a/plugins/techdocs-node/src/stages/publish/googleStorage.ts b/plugins/techdocs-node/src/stages/publish/googleStorage.ts index 987dfc6f09..7e862722a7 100644 --- a/plugins/techdocs-node/src/stages/publish/googleStorage.ts +++ b/plugins/techdocs-node/src/stages/publish/googleStorage.ts @@ -274,18 +274,14 @@ export class GoogleGCSPublish implements PublisherBase { */ docsRouter(): express.Handler { return (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 From e3d7ce12e395ebb57a13af3b1b4a110675f5246e Mon Sep 17 00:00:00 2001 From: aarontsharp Date: Tue, 30 Aug 2022 08:48:09 -0700 Subject: [PATCH 3/3] clearer patch message Signed-off-by: aarontsharp --- .changeset/big-spies-check.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/big-spies-check.md b/.changeset/big-spies-check.md index 6f8c3208ee..c704c7d00e 100644 --- a/.changeset/big-spies-check.md +++ b/.changeset/big-spies-check.md @@ -2,4 +2,4 @@ '@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 +Fix Techdocs S3 and GCS publisher to include bucketRootPath in requests