Skip to content

Commit

Permalink
feat: support node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Jun 1, 2022
1 parent 9dc9a94 commit 5ee5c29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
# Include all major maintenance + active LTS + current Node.js versions.
# https://github.com/nodejs/Release#release-schedule
node: [14, 16]
node: [14, 16, 18]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
13 changes: 12 additions & 1 deletion src/node/NodeWebSocketTransport.ts
Expand Up @@ -16,9 +16,20 @@
import NodeWebSocket from 'ws';
import { ConnectionTransport } from '../common/ConnectionTransport.js';
import { packageVersion } from '../generated/version.js';
import { promises as dns } from 'dns';

export class NodeWebSocketTransport implements ConnectionTransport {
static create(url: string): Promise<NodeWebSocketTransport> {
static async create(urlString: string): Promise<NodeWebSocketTransport> {
// Starting in Node 17, IPv6 is favoured over IPv4 due to a change in a default
// option:
// - https://github.com/nodejs/node/issues/40537,
// Due to this, we parse and resolve the hostname manually with the previous
// behavior according to:
// - https://nodejs.org/api/dns.html#dnslookuphostname-options-callback
const url = new URL(urlString);
const { address } = await dns.lookup(url.hostname, { verbatim: false });
url.hostname = address;

return new Promise((resolve, reject) => {
const ws = new NodeWebSocket(url, [], {
followRedirects: true,
Expand Down

0 comments on commit 5ee5c29

Please sign in to comment.