fix(techdocs): update proxy endpoint for serve command

Signed-off-by: Chris Trombley <ctrombley@gmail.com>
This commit is contained in:
Chris Trombley
2022-05-11 11:36:23 -07:00
parent 52ce9d94e9
commit 201d0d31bb
2 changed files with 9 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@techdocs/cli': patch
---
Update `techdocs-cli serve`'s `proxyEndpoint` to match the base URL of the embedded techdocs app.
+4 -5
View File
@@ -32,7 +32,7 @@ export default class HTTPServer {
mkdocsPort: number,
verbose: boolean,
) {
this.proxyEndpoint = '/api/';
this.proxyEndpoint = '/api/techdocs/';
this.backstageBundleDir = backstageBundleDir;
this.backstagePort = backstagePort;
this.mkdocsPort = mkdocsPort;
@@ -46,10 +46,9 @@ export default class HTTPServer {
});
return (request: http.IncomingMessage): [httpProxy, string] => {
// If the request goes to /api/ we want to remove /api/ from the prefix of the request URL.
// e.g. ['/', 'api', pathChunks]
const [, , ...pathChunks] = request.url?.split('/') ?? [];
const forwardPath = pathChunks.join('/');
// If the request path is prefixed with this.proxyEndpoint, remove it.
const proxyEndpointPath = new RegExp(`^${this.proxyEndpoint}`, 'i');
const forwardPath = request.url?.replace(proxyEndpointPath, '') || '';
return [proxy, forwardPath];
};