@whatwg-node/server 0.5.2 → 0.5.4-alpha-20230102102521-2e7c4e5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -12,22 +12,26 @@ function getPort(nodeRequest) {
12
12
  if ((_a = nodeRequest.socket) === null || _a === void 0 ? void 0 : _a.localPort) {
13
13
  return (_b = nodeRequest.socket) === null || _b === void 0 ? void 0 : _b.localPort;
14
14
  }
15
- const portInHeader = (_e = (_d = (_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c.host) === null || _d === void 0 ? void 0 : _d.split(':')) === null || _e === void 0 ? void 0 : _e[1];
15
+ const hostInHeader = ((_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c[':authority']) || ((_d = nodeRequest.headers) === null || _d === void 0 ? void 0 : _d.host);
16
+ const portInHeader = (_e = hostInHeader === null || hostInHeader === void 0 ? void 0 : hostInHeader.split(':')) === null || _e === void 0 ? void 0 : _e[1];
16
17
  if (portInHeader) {
17
18
  return portInHeader;
18
19
  }
19
20
  return 80;
20
21
  }
21
22
  function getHostnameWithPort(nodeRequest) {
22
- var _a, _b, _c;
23
- if ((_a = nodeRequest.headers) === null || _a === void 0 ? void 0 : _a.host) {
24
- return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b.host;
23
+ var _a, _b, _c, _d, _e;
24
+ if ((_a = nodeRequest.headers) === null || _a === void 0 ? void 0 : _a[':authority']) {
25
+ return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b[':authority'];
26
+ }
27
+ if ((_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c.host) {
28
+ return (_d = nodeRequest.headers) === null || _d === void 0 ? void 0 : _d.host;
25
29
  }
26
30
  const port = getPort(nodeRequest);
27
31
  if (nodeRequest.hostname) {
28
32
  return nodeRequest.hostname + ':' + port;
29
33
  }
30
- const localIp = (_c = nodeRequest.socket) === null || _c === void 0 ? void 0 : _c.localAddress;
34
+ const localIp = (_e = nodeRequest.socket) === null || _e === void 0 ? void 0 : _e.localAddress;
31
35
  if (localIp && !(localIp === null || localIp === void 0 ? void 0 : localIp.includes('::')) && !(localIp === null || localIp === void 0 ? void 0 : localIp.includes('ffff'))) {
32
36
  return `${localIp}:${port}`;
33
37
  }
package/index.mjs CHANGED
@@ -9,22 +9,26 @@ function getPort(nodeRequest) {
9
9
  if ((_a = nodeRequest.socket) === null || _a === void 0 ? void 0 : _a.localPort) {
10
10
  return (_b = nodeRequest.socket) === null || _b === void 0 ? void 0 : _b.localPort;
11
11
  }
12
- const portInHeader = (_e = (_d = (_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c.host) === null || _d === void 0 ? void 0 : _d.split(':')) === null || _e === void 0 ? void 0 : _e[1];
12
+ const hostInHeader = ((_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c[':authority']) || ((_d = nodeRequest.headers) === null || _d === void 0 ? void 0 : _d.host);
13
+ const portInHeader = (_e = hostInHeader === null || hostInHeader === void 0 ? void 0 : hostInHeader.split(':')) === null || _e === void 0 ? void 0 : _e[1];
13
14
  if (portInHeader) {
14
15
  return portInHeader;
15
16
  }
16
17
  return 80;
17
18
  }
18
19
  function getHostnameWithPort(nodeRequest) {
19
- var _a, _b, _c;
20
- if ((_a = nodeRequest.headers) === null || _a === void 0 ? void 0 : _a.host) {
21
- return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b.host;
20
+ var _a, _b, _c, _d, _e;
21
+ if ((_a = nodeRequest.headers) === null || _a === void 0 ? void 0 : _a[':authority']) {
22
+ return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b[':authority'];
23
+ }
24
+ if ((_c = nodeRequest.headers) === null || _c === void 0 ? void 0 : _c.host) {
25
+ return (_d = nodeRequest.headers) === null || _d === void 0 ? void 0 : _d.host;
22
26
  }
23
27
  const port = getPort(nodeRequest);
24
28
  if (nodeRequest.hostname) {
25
29
  return nodeRequest.hostname + ':' + port;
26
30
  }
27
- const localIp = (_c = nodeRequest.socket) === null || _c === void 0 ? void 0 : _c.localAddress;
31
+ const localIp = (_e = nodeRequest.socket) === null || _e === void 0 ? void 0 : _e.localAddress;
28
32
  if (localIp && !(localIp === null || localIp === void 0 ? void 0 : localIp.includes('::')) && !(localIp === null || localIp === void 0 ? void 0 : localIp.includes('ffff'))) {
29
33
  return `${localIp}:${port}`;
30
34
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@whatwg-node/server",
3
- "version": "0.5.2",
3
+ "version": "0.5.4-alpha-20230102102521-2e7c4e5",
4
4
  "description": "Fetch API compliant HTTP Server adapter",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "@types/node": "^18.0.6"
8
8
  },
9
9
  "dependencies": {
10
- "@whatwg-node/fetch": "0.6.0",
10
+ "@whatwg-node/fetch": "0.6.2-alpha-20230102102521-2e7c4e5",
11
11
  "tslib": "^2.3.1"
12
12
  },
13
13
  "repository": {
package/utils.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
4
  /// <reference types="node" />
5
- import { IncomingMessage, ServerResponse } from 'node:http';
5
+ import type { IncomingMessage, ServerResponse } from 'node:http';
6
6
  import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
7
7
  import type { Socket } from 'node:net';
8
8
  import type { Readable } from 'node:stream';