Skip to content

Commit

Permalink
fix: address.family is number in Node v18
Browse files Browse the repository at this point in the history
See nodejs/node#41431

Signed-off-by: Francisco Buceta <frbuceta@gmail.com>
  • Loading branch information
frbuceta committed May 2, 2022
1 parent ff8cbff commit e45cafa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('HttpServer (integration)', () => {
host: '::1',
} as HttpOptions);
await server.start();
expect(getAddressFamily(server)).to.equal('IPv6');
expect(getAddressFamily(server)).to.equalOneOf(6, 'IPv6');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});
Expand Down Expand Up @@ -225,15 +225,15 @@ describe('HttpServer (integration)', () => {
it('supports HTTP over IPv4', async () => {
server = new HttpServer(dummyRequestHandler, {host: '127.0.0.1'});
await server.start();
expect(getAddressFamily(server)).to.equal('IPv4');
expect(getAddressFamily(server)).to.equalOneOf(4, 'IPv4');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});

skipOnTravis(it, 'supports HTTP over IPv6', async () => {
server = new HttpServer(dummyRequestHandler, {host: '::1'});
await server.start();
expect(getAddressFamily(server)).to.equal('IPv6');
expect(getAddressFamily(server)).to.equalOneOf(6, 'IPv6');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});
Expand All @@ -258,7 +258,7 @@ describe('HttpServer (integration)', () => {
host: '::1',
});
await httpsServer.start();
expect(getAddressFamily(httpsServer)).to.equal('IPv6');
expect(getAddressFamily(httpsServer)).to.equalOneOf(6, 'IPv6');
const response = await httpsGetAsync(httpsServer.url);
expect(response.statusCode).to.equal(200);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/http-server/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class HttpServer {
return `${this.protocol}+unix://${basePath}`;
}
let host = this.host;
if (this._address.family === 'IPv6') {
if ([6, 'IPv6'].includes(this._address.family)) {
if (host === '::') host = '::1';
host = `[${host}]`;
} else if (host === '0.0.0.0') {
Expand Down

0 comments on commit e45cafa

Please sign in to comment.