@whatwg-node/server 0.5.7 → 0.5.9-alpha-20230126122734-e16acbb
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/README.md +2 -2
- package/index.js +25 -19
- package/index.mjs +25 -19
- package/package.json +2 -5
- package/utils.d.ts +1 -1
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ app.route({
|
|
|
127
127
|
|
|
128
128
|
reply.status(response.status)
|
|
129
129
|
|
|
130
|
-
reply.send(
|
|
130
|
+
reply.send(response.body)
|
|
131
131
|
|
|
132
132
|
return reply
|
|
133
133
|
}
|
|
@@ -157,7 +157,7 @@ app.use(async ctx => {
|
|
|
157
157
|
ctx.append(key, value)
|
|
158
158
|
})
|
|
159
159
|
|
|
160
|
-
ctx.body =
|
|
160
|
+
ctx.body = response.body
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
app.listen(4000, () => {
|
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
|
|
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
|
|
24
|
-
return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b
|
|
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 = (
|
|
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
|
}
|
|
@@ -341,20 +345,22 @@ RequestCtor = fetch.Request) {
|
|
|
341
345
|
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#copying_accessors
|
|
342
346
|
function completeAssign(target, ...sources) {
|
|
343
347
|
sources.forEach(source => {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
descriptors
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
348
|
+
if (source != null && typeof source === 'object') {
|
|
349
|
+
// modified Object.keys to Object.getOwnPropertyNames
|
|
350
|
+
// because Object.keys only returns enumerable properties
|
|
351
|
+
const descriptors = Object.getOwnPropertyNames(source).reduce((descriptors, key) => {
|
|
352
|
+
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
|
|
353
|
+
return descriptors;
|
|
354
|
+
}, {});
|
|
355
|
+
// By default, Object.assign copies enumerable Symbols, too
|
|
356
|
+
Object.getOwnPropertySymbols(source).forEach(sym => {
|
|
357
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, sym);
|
|
358
|
+
if (descriptor.enumerable) {
|
|
359
|
+
descriptors[sym] = descriptor;
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
Object.defineProperties(target, descriptors);
|
|
363
|
+
}
|
|
358
364
|
});
|
|
359
365
|
return target;
|
|
360
366
|
}
|
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
|
|
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
|
|
21
|
-
return (_b = nodeRequest.headers) === null || _b === void 0 ? void 0 : _b
|
|
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 = (
|
|
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
|
}
|
|
@@ -338,20 +342,22 @@ RequestCtor = Request) {
|
|
|
338
342
|
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#copying_accessors
|
|
339
343
|
function completeAssign(target, ...sources) {
|
|
340
344
|
sources.forEach(source => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
descriptors
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
345
|
+
if (source != null && typeof source === 'object') {
|
|
346
|
+
// modified Object.keys to Object.getOwnPropertyNames
|
|
347
|
+
// because Object.keys only returns enumerable properties
|
|
348
|
+
const descriptors = Object.getOwnPropertyNames(source).reduce((descriptors, key) => {
|
|
349
|
+
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
|
|
350
|
+
return descriptors;
|
|
351
|
+
}, {});
|
|
352
|
+
// By default, Object.assign copies enumerable Symbols, too
|
|
353
|
+
Object.getOwnPropertySymbols(source).forEach(sym => {
|
|
354
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, sym);
|
|
355
|
+
if (descriptor.enumerable) {
|
|
356
|
+
descriptors[sym] = descriptor;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
Object.defineProperties(target, descriptors);
|
|
360
|
+
}
|
|
355
361
|
});
|
|
356
362
|
return target;
|
|
357
363
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatwg-node/server",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9-alpha-20230126122734-e16acbb",
|
|
4
4
|
"description": "Fetch API compliant HTTP Server adapter",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"peerDependencies": {
|
|
7
|
-
"@types/node": "^18.0.6"
|
|
8
|
-
},
|
|
9
6
|
"dependencies": {
|
|
10
|
-
"@whatwg-node/fetch": "0.6.
|
|
7
|
+
"@whatwg-node/fetch": "0.6.3-alpha-20230126122734-e16acbb",
|
|
11
8
|
"tslib": "^2.3.1"
|
|
12
9
|
},
|
|
13
10
|
"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';
|