Merge pull request #11467 from ctrombley/fix/techdocs-cli-serve

fix(techdocs): update proxy endpoint for `techdocs-cli serve` command
This commit is contained in:
Eric Peterson
2022-05-16 09:45:31 +02:00
committed by GitHub
2 changed files with 9 additions and 5 deletions
@@ -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];
};