Skip to content

Commit 71f8fc2

Browse files
committed
fix(techdocs-cli): Fix proxying to mkdocs
The domain localhost may point to both 127.0.0.1 and ::1, ipv4 and ipv6 and when node tries to lookup localhost it might prefer ipv6 while mkdocs is only listening on ipv4. This tells node-proxy to target the ipv4 address instead of relying on localhost hostname lookup. Signed-off-by: Nikolai R Kristiansen <[email protected]>
1 parent 3197a81 commit 71f8fc2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/techdocs-cli/src/commands/serve/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default async function serve(opts: OptionValues) {
127127
const httpServer = new HTTPServer(
128128
previewAppPath,
129129
port,
130-
opts.mkdocsPort,
130+
mkdocsExpectedDevAddr,
131131
opts.verbose,
132132
);
133133

packages/techdocs-cli/src/lib/httpServer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ export default class HTTPServer {
2323
private readonly proxyEndpoint: string;
2424
private readonly backstageBundleDir: string;
2525
private readonly backstagePort: number;
26-
private readonly mkdocsPort: number;
26+
private readonly mkdocsTargetAddress: string;
2727
private readonly verbose: boolean;
2828

2929
constructor(
3030
backstageBundleDir: string,
3131
backstagePort: number,
32-
mkdocsPort: number,
32+
mkdocsTargetAddress: string,
3333
verbose: boolean,
3434
) {
3535
this.proxyEndpoint = '/api/techdocs/';
3636
this.backstageBundleDir = backstageBundleDir;
3737
this.backstagePort = backstagePort;
38-
this.mkdocsPort = mkdocsPort;
38+
this.mkdocsTargetAddress = mkdocsTargetAddress;
3939
this.verbose = verbose;
4040
}
4141

4242
// Create a Proxy for mkdocs server
4343
private createProxy() {
4444
const proxy = httpProxy.createProxyServer({
45-
target: `http://localhost:${this.mkdocsPort}`,
45+
target: this.mkdocsTargetAddress,
4646
});
4747

4848
return (request: http.IncomingMessage): [httpProxy, string] => {

0 commit comments

Comments
 (0)