Skip to content

Commit

Permalink
fix node 18 ipv6 address
Browse files Browse the repository at this point in the history
Node 18.x seems to default to an IPv6 localhost address by default now.

Force hostname default to `localhost`.
  • Loading branch information
paul-marechal committed May 27, 2022
1 parent 7322adb commit aeb9ab2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion dev-packages/cli/src/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ export default async function runTest(options: TestOptions): Promise<void> {
});

const server = await start();
await testPage.goto(`http://${server.address}:${server.port}`);
if (net.isIPv6(server.address)) {
// IPv6 addresses must be put in brackets for URLs to work:
await testPage.goto(`http://[${server.address}]:${server.port}`);
} else {
await testPage.goto(`http://${server.address}:${server.port}`);
}
}
6 changes: 3 additions & 3 deletions packages/core/src/node/backend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ export class BackendApplication {
}

async start(aPort?: number, aHostname?: string): Promise<http.Server | https.Server> {
const hostname = aHostname !== undefined ? aHostname : this.cliParams.hostname;
const port = aPort !== undefined ? aPort : this.cliParams.port;
const hostname: string = aHostname ?? this.cliParams.hostname ?? 'localhost';
const port: number = aPort ?? this.cliParams.port ?? 3000;

const deferred = new Deferred<http.Server | https.Server>();
let server: http.Server | https.Server;
Expand Down Expand Up @@ -277,7 +277,7 @@ export class BackendApplication {

server.listen(port, hostname, () => {
const scheme = this.cliParams.ssl ? 'https' : 'http';
console.info(`Theia app listening on ${scheme}://${hostname || 'localhost'}:${(server.address() as AddressInfo).port}.`);
console.info(`Theia app listening on ${scheme}://${hostname}:${(server.address() as AddressInfo).port}.`);
deferred.resolve(server);
});

Expand Down

0 comments on commit aeb9ab2

Please # to comment.