@effect/platform-node 4.0.0-beta.8 → 4.0.0-beta.81
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/dist/Mime.d.ts +9 -3
- package/dist/Mime.d.ts.map +1 -1
- package/dist/Mime.js +9 -3
- package/dist/Mime.js.map +1 -1
- package/dist/NodeChildProcessSpawner.d.ts +1 -1
- package/dist/NodeChildProcessSpawner.js +1 -1
- package/dist/NodeClusterHttp.d.ts +25 -7
- package/dist/NodeClusterHttp.d.ts.map +1 -1
- package/dist/NodeClusterHttp.js +20 -10
- package/dist/NodeClusterHttp.js.map +1 -1
- package/dist/NodeClusterSocket.d.ts +37 -11
- package/dist/NodeClusterSocket.d.ts.map +1 -1
- package/dist/NodeClusterSocket.js +37 -11
- package/dist/NodeClusterSocket.js.map +1 -1
- package/dist/NodeCrypto.d.ts +10 -0
- package/dist/NodeCrypto.d.ts.map +1 -0
- package/dist/NodeCrypto.js +22 -0
- package/dist/NodeCrypto.js.map +1 -0
- package/dist/NodeFileSystem.d.ts +4 -2
- package/dist/NodeFileSystem.d.ts.map +1 -1
- package/dist/NodeFileSystem.js +12 -3
- package/dist/NodeFileSystem.js.map +1 -1
- package/dist/NodeHttpClient.d.ts +98 -29
- package/dist/NodeHttpClient.d.ts.map +1 -1
- package/dist/NodeHttpClient.js +120 -33
- package/dist/NodeHttpClient.js.map +1 -1
- package/dist/NodeHttpIncomingMessage.d.ts +36 -9
- package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
- package/dist/NodeHttpIncomingMessage.js +40 -8
- package/dist/NodeHttpIncomingMessage.js.map +1 -1
- package/dist/NodeHttpPlatform.d.ts +10 -4
- package/dist/NodeHttpPlatform.d.ts.map +1 -1
- package/dist/NodeHttpPlatform.js +20 -7
- package/dist/NodeHttpPlatform.js.map +1 -1
- package/dist/NodeHttpServer.d.ts +59 -19
- package/dist/NodeHttpServer.d.ts.map +1 -1
- package/dist/NodeHttpServer.js +102 -52
- package/dist/NodeHttpServer.js.map +1 -1
- package/dist/NodeHttpServerRequest.d.ts +18 -5
- package/dist/NodeHttpServerRequest.d.ts.map +1 -1
- package/dist/NodeHttpServerRequest.js +11 -4
- package/dist/NodeHttpServerRequest.js.map +1 -1
- package/dist/NodeMultipart.d.ts +24 -4
- package/dist/NodeMultipart.d.ts.map +1 -1
- package/dist/NodeMultipart.js +24 -4
- package/dist/NodeMultipart.js.map +1 -1
- package/dist/NodePath.d.ts +15 -6
- package/dist/NodePath.d.ts.map +1 -1
- package/dist/NodePath.js +23 -7
- package/dist/NodePath.js.map +1 -1
- package/dist/NodeRedis.d.ts +27 -9
- package/dist/NodeRedis.d.ts.map +1 -1
- package/dist/NodeRedis.js +30 -12
- package/dist/NodeRedis.js.map +1 -1
- package/dist/NodeRuntime.d.ts +27 -36
- package/dist/NodeRuntime.d.ts.map +1 -1
- package/dist/NodeRuntime.js +17 -13
- package/dist/NodeRuntime.js.map +1 -1
- package/dist/NodeServices.d.ts +19 -5
- package/dist/NodeServices.d.ts.map +1 -1
- package/dist/NodeServices.js +7 -3
- package/dist/NodeServices.js.map +1 -1
- package/dist/NodeSink.d.ts +2 -2
- package/dist/NodeSink.js +2 -2
- package/dist/NodeSocket.d.ts +18 -3
- package/dist/NodeSocket.d.ts.map +1 -1
- package/dist/NodeSocket.js +27 -4
- package/dist/NodeSocket.js.map +1 -1
- package/dist/NodeSocketServer.d.ts +2 -2
- package/dist/NodeSocketServer.js +2 -2
- package/dist/NodeStdio.d.ts +5 -2
- package/dist/NodeStdio.d.ts.map +1 -1
- package/dist/NodeStdio.js +13 -3
- package/dist/NodeStdio.js.map +1 -1
- package/dist/NodeStream.d.ts +2 -2
- package/dist/NodeStream.js +2 -2
- package/dist/NodeTerminal.d.ts +8 -2
- package/dist/NodeTerminal.d.ts.map +1 -1
- package/dist/NodeTerminal.js +15 -3
- package/dist/NodeTerminal.js.map +1 -1
- package/dist/NodeWorker.d.ts +9 -2
- package/dist/NodeWorker.d.ts.map +1 -1
- package/dist/NodeWorker.js +22 -6
- package/dist/NodeWorker.js.map +1 -1
- package/dist/NodeWorkerRunner.d.ts +5 -1
- package/dist/NodeWorkerRunner.d.ts.map +1 -1
- package/dist/NodeWorkerRunner.js +18 -5
- package/dist/NodeWorkerRunner.js.map +1 -1
- package/dist/Undici.d.ts +18 -5
- package/dist/Undici.d.ts.map +1 -1
- package/dist/Undici.js +18 -5
- package/dist/Undici.js.map +1 -1
- package/dist/index.d.ts +28 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -26
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/Mime.ts +10 -3
- package/src/NodeChildProcessSpawner.ts +1 -1
- package/src/NodeClusterHttp.ts +30 -11
- package/src/NodeClusterSocket.ts +37 -11
- package/src/NodeCrypto.ts +24 -0
- package/src/NodeFileSystem.ts +12 -3
- package/src/NodeHttpClient.ts +128 -38
- package/src/NodeHttpIncomingMessage.ts +48 -12
- package/src/NodeHttpPlatform.ts +21 -6
- package/src/NodeHttpServer.ts +124 -56
- package/src/NodeHttpServerRequest.ts +18 -5
- package/src/NodeMultipart.ts +24 -4
- package/src/NodePath.ts +23 -7
- package/src/NodeRedis.ts +32 -14
- package/src/NodeRuntime.ts +35 -37
- package/src/NodeServices.ts +21 -5
- package/src/NodeSink.ts +2 -2
- package/src/NodeSocket.ts +32 -4
- package/src/NodeSocketServer.ts +2 -2
- package/src/NodeStdio.ts +13 -3
- package/src/NodeStream.ts +2 -2
- package/src/NodeTerminal.ts +15 -3
- package/src/NodeWorker.ts +22 -6
- package/src/NodeWorkerRunner.ts +18 -5
- package/src/Undici.ts +18 -5
- package/src/index.ts +29 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeHttpIncomingMessage.d.ts","sourceRoot":"","sources":["../src/NodeHttpIncomingMessage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"NodeHttpIncomingMessage.d.ts","sourceRoot":"","sources":["../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AE,CAAC,CAAC,CAgBnC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAMxC;IAED,IAAI,UAAU,IAAI,MAAM,CAAC,IAAI,CAE5B;IAED,IAAI,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAMzD;IAED,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAKzC;IAED,OAAO,CAAC,iBAAiB,CAA2C;IACpE,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAe/C;CACF"}
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Adapter base for exposing Node `http.IncomingMessage` values as Effect HTTP
|
|
3
|
+
* incoming messages.
|
|
4
|
+
*
|
|
5
|
+
* Server requests and Node client responses both arrive as Node readable
|
|
6
|
+
* streams with raw header objects, socket metadata, and one-shot body
|
|
7
|
+
* consumption. This module's `NodeHttpIncomingMessage` class keeps the original
|
|
8
|
+
* Node message available while presenting Effect's `HttpIncomingMessage` shape:
|
|
9
|
+
* typed headers, remote address lookup, stream access, and text, JSON,
|
|
10
|
+
* URL-encoded, and array-buffer body readers.
|
|
11
|
+
*
|
|
12
|
+
* @since 4.0.0
|
|
3
13
|
*/
|
|
4
14
|
import * as Effect from "effect/Effect";
|
|
5
15
|
import * as Inspectable from "effect/Inspectable";
|
|
16
|
+
import * as Option from "effect/Option";
|
|
6
17
|
import * as Headers from "effect/unstable/http/Headers";
|
|
7
18
|
import * as IncomingMessage from "effect/unstable/http/HttpIncomingMessage";
|
|
8
19
|
import * as UrlParams from "effect/unstable/http/UrlParams";
|
|
9
20
|
import * as NodeStream from "./NodeStream.js";
|
|
10
21
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
22
|
+
* Adapts a Node `IncomingMessage` to Effect HTTP incoming messages.
|
|
23
|
+
*
|
|
24
|
+
* **When to use**
|
|
25
|
+
*
|
|
26
|
+
* Use to implement Node HTTP request or response adapters that expose the
|
|
27
|
+
* Effect HTTP incoming-message interface.
|
|
28
|
+
*
|
|
29
|
+
* **Details**
|
|
30
|
+
*
|
|
31
|
+
* The adapter exposes headers, remote address, stream access, and cached body
|
|
32
|
+
* decoders. Subclasses provide the error mapping for unknown Node errors.
|
|
33
|
+
*
|
|
34
|
+
* @category constructors
|
|
35
|
+
* @since 4.0.0
|
|
13
36
|
*/
|
|
14
37
|
export class NodeHttpIncomingMessage extends Inspectable.Class {
|
|
15
38
|
/**
|
|
16
|
-
*
|
|
39
|
+
* Marks this value as an HTTP incoming message for runtime guards.
|
|
40
|
+
*
|
|
41
|
+
* @since 4.0.0
|
|
17
42
|
*/
|
|
18
43
|
[IncomingMessage.TypeId];
|
|
19
44
|
source;
|
|
@@ -30,17 +55,18 @@ export class NodeHttpIncomingMessage extends Inspectable.Class {
|
|
|
30
55
|
return Headers.fromInput(this.source.headers);
|
|
31
56
|
}
|
|
32
57
|
get remoteAddress() {
|
|
33
|
-
return this.remoteAddressOverride ?? this.source.socket.remoteAddress;
|
|
58
|
+
return this.remoteAddressOverride ?? Option.fromNullishOr(this.source.socket.remoteAddress);
|
|
34
59
|
}
|
|
35
60
|
textEffect;
|
|
36
61
|
get text() {
|
|
37
62
|
if (this.textEffect) {
|
|
38
63
|
return this.textEffect;
|
|
39
64
|
}
|
|
40
|
-
this.textEffect = Effect.runSync(Effect.cached(Effect.flatMap(IncomingMessage.MaxBodySize
|
|
65
|
+
this.textEffect = Effect.runSync(Effect.cached(Effect.flatMap(IncomingMessage.MaxBodySize, maxBodySize => NodeStream.toString(() => this.source, {
|
|
41
66
|
onError: this.onError,
|
|
42
67
|
maxBytes: maxBodySize
|
|
43
68
|
}))));
|
|
69
|
+
this.arrayBufferEffect = Effect.map(this.textEffect, _ => new TextEncoder().encode(_).buffer);
|
|
44
70
|
return this.textEffect;
|
|
45
71
|
}
|
|
46
72
|
get textUnsafe() {
|
|
@@ -67,11 +93,17 @@ export class NodeHttpIncomingMessage extends Inspectable.Class {
|
|
|
67
93
|
onError: this.onError
|
|
68
94
|
});
|
|
69
95
|
}
|
|
96
|
+
arrayBufferEffect;
|
|
70
97
|
get arrayBuffer() {
|
|
71
|
-
|
|
98
|
+
if (this.arrayBufferEffect) {
|
|
99
|
+
return this.arrayBufferEffect;
|
|
100
|
+
}
|
|
101
|
+
this.arrayBufferEffect = Effect.withFiber(fiber => NodeStream.toArrayBuffer(() => this.source, {
|
|
72
102
|
onError: this.onError,
|
|
73
103
|
maxBytes: fiber.getRef(IncomingMessage.MaxBodySize)
|
|
74
|
-
}));
|
|
104
|
+
})).pipe(Effect.cached, Effect.runSync);
|
|
105
|
+
this.textEffect = Effect.map(this.arrayBufferEffect, _ => new TextDecoder().decode(_));
|
|
106
|
+
return this.arrayBufferEffect;
|
|
75
107
|
}
|
|
76
108
|
}
|
|
77
109
|
//# sourceMappingURL=NodeHttpIncomingMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeHttpIncomingMessage.js","names":["Effect","Inspectable","Headers","IncomingMessage","UrlParams","NodeStream","NodeHttpIncomingMessage","Class","TypeId","source","onError","remoteAddressOverride","constructor","headers","fromInput","remoteAddress","socket","textEffect","text","runSync","cached","flatMap","MaxBodySize","
|
|
1
|
+
{"version":3,"file":"NodeHttpIncomingMessage.js","names":["Effect","Inspectable","Option","Headers","IncomingMessage","UrlParams","NodeStream","NodeHttpIncomingMessage","Class","TypeId","source","onError","remoteAddressOverride","constructor","headers","fromInput","remoteAddress","fromNullishOr","socket","textEffect","text","runSync","cached","flatMap","MaxBodySize","maxBodySize","toString","maxBytes","arrayBufferEffect","map","_","TextEncoder","encode","buffer","textUnsafe","json","try","JSON","parse","catch","jsonUnsafe","urlParamsBody","URLSearchParams","stream","fromReadable","evaluate","arrayBuffer","withFiber","fiber","toArrayBuffer","getRef","pipe","TextDecoder","decode"],"sources":["../src/NodeHttpIncomingMessage.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;AAaA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,WAAW,MAAM,oBAAoB;AACjD,OAAO,KAAKC,MAAM,MAAM,eAAe;AAGvC,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAAKC,eAAe,MAAM,0CAA0C;AAC3E,OAAO,KAAKC,SAAS,MAAM,gCAAgC;AAE3D,OAAO,KAAKC,UAAU,MAAM,iBAAiB;AAE7C;;;;;;;;;;;;;;;;AAgBA,OAAM,MAAgBC,uBAA2B,SAAQN,WAAW,CAACO,KAAK;EAGxE;;;;;EAKS,CAACJ,eAAe,CAACK,MAAM;EACvBC,MAAM;EACNC,OAAO;EACPC,qBAAqB;EAE9BC,YACEH,MAA4B,EAC5BC,OAA8B,EAC9BC,qBAA6C;IAE7C,KAAK,EAAE;IACP,IAAI,CAACR,eAAe,CAACK,MAAM,CAAC,GAAGL,eAAe,CAACK,MAAM;IACrD,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,qBAAqB,GAAGA,qBAAqB;EACpD;EAEA,IAAIE,OAAOA,CAAA;IACT,OAAOX,OAAO,CAACY,SAAS,CAAC,IAAI,CAACL,MAAM,CAACI,OAAc,CAAC;EACtD;EAEA,IAAIE,aAAaA,CAAA;IACf,OAAO,IAAI,CAACJ,qBAAqB,IAAIV,MAAM,CAACe,aAAa,CAAC,IAAI,CAACP,MAAM,CAACQ,MAAM,CAACF,aAAa,CAAC;EAC7F;EAEQG,UAAU;EAClB,IAAIC,IAAIA,CAAA;IACN,IAAI,IAAI,CAACD,UAAU,EAAE;MACnB,OAAO,IAAI,CAACA,UAAU;IACxB;IACA,IAAI,CAACA,UAAU,GAA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AC,CAAC;EACP;EAEA,IAAIgC,MAAMA,CAAA;IACR,OAAOrC,UAAU,CAACsC,YAAY,CAAC;MAC7BC,QAAQ,EAAEA,CAAA,KAAM,IAAI,CAACnC,MAAM;MAC3BC,OAAO,EAAE,IAAI,CAACA;KACf,CAAC;EACJ;EAEQiB,iBAAiB;EACzB,IAAIkB,WAAWA,CAAA;IACb,IAAI,IAAI,CAAClB,iBAAiB,EAAE;MAC1B,OAAO,IAAI,CAACA,iBAAiB;IAC/B;IACA,IAAI,CAACA,iBAAiB,GAAG5B,MAAM,CAAC+C,SAAS,CAAEC,KAAK,IAC9C1C,UAAU,CAAC2C,aAAa,CAAC,MAAM,IAAI,CAACvC,MAAM,EAAE;MAC1CC,OAAO,EAAE,IAAI,CAACA,OAAO;MACrBgB,QAAQ,EAAEqB,KAAK,CAACE,MAAM,CAAC9C,eAAe,CAACoB,WAAW;KACnD,CAAC,CACH,CAAC2B,IAAI,CACJnD,MAAM,CAACsB,MAAM,EACbtB,MAAM,CAACqB,OAAO,CACf;IACD,IAAI,CAACF,UAAU,GAAGnB,MAAM,CAAC6B,GAAG,CAAC,IAAI,CAACD,iBAAiB,EAAGE,CAAC,IAAK,IAAIsB,WAAW,EAAE,CAACC,MAAM,CAACvB,CAAC,CAAC,CAAC;IACxF,OAAO,IAAI,CAACF,iBAAiB;EAC/B","ignoreList":[]}
|
|
@@ -3,8 +3,11 @@ import * as EtagImpl from "effect/unstable/http/Etag";
|
|
|
3
3
|
import * as Platform from "effect/unstable/http/HttpPlatform";
|
|
4
4
|
import * as ServerResponse from "effect/unstable/http/HttpServerResponse";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Creates the Node `HttpPlatform`, serving file responses from Node readable
|
|
7
|
+
* streams and adding MIME type and content-length headers when needed.
|
|
8
|
+
*
|
|
9
|
+
* @category constructors
|
|
10
|
+
* @since 4.0.0
|
|
8
11
|
*/
|
|
9
12
|
export declare const make: import("effect/Effect").Effect<{
|
|
10
13
|
readonly fileResponse: (path: string, options?: ServerResponse.Options.WithContent & {
|
|
@@ -19,8 +22,11 @@ export declare const make: import("effect/Effect").Effect<{
|
|
|
19
22
|
}) => import("effect/Effect").Effect<ServerResponse.HttpServerResponse>;
|
|
20
23
|
}, never, import("effect/FileSystem").FileSystem | EtagImpl.Generator>;
|
|
21
24
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
25
|
+
* Provides the Node `HttpPlatform` together with the filesystem and ETag
|
|
26
|
+
* services it needs for file responses.
|
|
27
|
+
*
|
|
28
|
+
* @category layers
|
|
29
|
+
* @since 4.0.0
|
|
24
30
|
*/
|
|
25
31
|
export declare const layer: Layer.Layer<Platform.HttpPlatform>;
|
|
26
32
|
//# sourceMappingURL=NodeHttpPlatform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeHttpPlatform.d.ts","sourceRoot":"","sources":["../src/NodeHttpPlatform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeHttpPlatform.d.ts","sourceRoot":"","sources":["../src/NodeHttpPlatform.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAErD,OAAO,KAAK,QAAQ,MAAM,mCAAmC,CAAA;AAC7D,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAA;AAMzE;;;;;;GAMG;AACH,eAAO,MAAM,IAAI;iDALkC,CAAC;4BAGtC,CAAC;0BAGM,CAAC;uBAClB,CAAD;;uGAGiB,CAAC;4BAGb,CAAA;0BAA8D,CAAC;uBAC1C,CAAC;;sEAmB5B,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAIpD,CAAA"}
|
package/dist/NodeHttpPlatform.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementation of the Effect HTTP platform service.
|
|
3
|
+
*
|
|
4
|
+
* This module connects the portable `HttpPlatform` file response helpers to
|
|
5
|
+
* Node runtime primitives. It serves local files through Node readable streams,
|
|
6
|
+
* supports byte ranges, converts Web `File` values to readable streams, and
|
|
7
|
+
* fills in content type and content length headers when needed.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import { pipe } from "effect/Function";
|
|
5
12
|
import * as Layer from "effect/Layer";
|
|
@@ -12,14 +19,17 @@ import { Readable } from "node:stream";
|
|
|
12
19
|
import Mime from "./Mime.js";
|
|
13
20
|
import * as NodeFileSystem from "./NodeFileSystem.js";
|
|
14
21
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
22
|
+
* Creates the Node `HttpPlatform`, serving file responses from Node readable
|
|
23
|
+
* streams and adding MIME type and content-length headers when needed.
|
|
24
|
+
*
|
|
25
|
+
* @category constructors
|
|
26
|
+
* @since 4.0.0
|
|
17
27
|
*/
|
|
18
28
|
export const make = /*#__PURE__*/Platform.make({
|
|
19
29
|
fileResponse(path, status, statusText, headers, start, end, contentLength) {
|
|
20
|
-
const stream = Fs.createReadStream(path, {
|
|
30
|
+
const stream = contentLength === 0 ? Readable.from([]) : Fs.createReadStream(path, {
|
|
21
31
|
start,
|
|
22
|
-
end
|
|
32
|
+
end: end === undefined ? undefined : end - 1
|
|
23
33
|
});
|
|
24
34
|
return ServerResponse.raw(stream, {
|
|
25
35
|
headers: {
|
|
@@ -43,8 +53,11 @@ export const make = /*#__PURE__*/Platform.make({
|
|
|
43
53
|
}
|
|
44
54
|
});
|
|
45
55
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
56
|
+
* Provides the Node `HttpPlatform` together with the filesystem and ETag
|
|
57
|
+
* services it needs for file responses.
|
|
58
|
+
*
|
|
59
|
+
* @category layers
|
|
60
|
+
* @since 4.0.0
|
|
48
61
|
*/
|
|
49
62
|
export const layer = /*#__PURE__*/pipe(/*#__PURE__*/Layer.effect(Platform.HttpPlatform)(make), /*#__PURE__*/Layer.provide(NodeFileSystem.layer), /*#__PURE__*/Layer.provide(EtagImpl.layer));
|
|
50
63
|
//# sourceMappingURL=NodeHttpPlatform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeHttpPlatform.js","names":["pipe","Layer","EtagImpl","Headers","Platform","ServerResponse","Fs","Readable","Mime","NodeFileSystem","make","fileResponse","path","status","statusText","headers","start","end","contentLength","stream","createReadStream","raw","getType","toString","fileWebResponse","file","_options","fromWeb","merge","fromRecordUnsafe","name","size","layer","effect","HttpPlatform","provide"],"sources":["../src/NodeHttpPlatform.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"NodeHttpPlatform.js","names":["pipe","Layer","EtagImpl","Headers","Platform","ServerResponse","Fs","Readable","Mime","NodeFileSystem","make","fileResponse","path","status","statusText","headers","start","end","contentLength","stream","from","createReadStream","undefined","raw","getType","toString","fileWebResponse","file","_options","fromWeb","merge","fromRecordUnsafe","name","size","layer","effect","HttpPlatform","provide"],"sources":["../src/NodeHttpPlatform.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;AAUA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,2BAA2B;AACrD,OAAO,KAAKC,OAAO,MAAM,8BAA8B;AACvD,OAAO,KAAKC,QAAQ,MAAM,mCAAmC;AAC7D,OAAO,KAAKC,cAAc,MAAM,yCAAyC;AACzE,OAAO,KAAKC,EAAE,MAAM,SAAS;AAC7B,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,IAAI,MAAM,WAAW;AAC5B,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;;;;;AAOA,OAAO,MAAMC,IAAI,gBAAGN,QAAQ,CAACM,IAAI,CAAC;EA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,CAACgC,YAAY,CAAC,CAAC1B,IAAI,CAAC,eACzCT,KAAK,CAACoC,OAAO,CAAC5B,cAAc,CAACyB,KAAK,CAAC,eACnCjC,KAAK,CAACoC,OAAO,CAACnC,QAAQ,CAACgC,KAAK,CAAC,CAC9B","ignoreList":[]}
|
package/dist/NodeHttpServer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
|
+
import * as Duration from "effect/Duration";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import type * as FileSystem from "effect/FileSystem";
|
|
4
5
|
import { type LazyArg } from "effect/Function";
|
|
@@ -19,10 +20,17 @@ import type { Duplex } from "node:stream";
|
|
|
19
20
|
import * as NodeServices from "./NodeServices.ts";
|
|
20
21
|
import { NodeWS } from "./NodeSocket.ts";
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* Creates a scoped `HttpServer` from a Node `http.Server`, starts listening
|
|
24
|
+
* with the supplied options, registers request and upgrade handling, and closes
|
|
25
|
+
* the server during scope finalization with optional graceful-shutdown control.
|
|
26
|
+
*
|
|
23
27
|
* @category constructors
|
|
28
|
+
* @since 4.0.0
|
|
24
29
|
*/
|
|
25
|
-
export declare const make: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>, options: Net.ListenOptions
|
|
30
|
+
export declare const make: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>, options: Net.ListenOptions & {
|
|
31
|
+
readonly disablePreemptiveShutdown?: boolean | undefined;
|
|
32
|
+
readonly gracefulShutdownTimeout?: Duration.Input | undefined;
|
|
33
|
+
}) => Effect.Effect<{
|
|
26
34
|
readonly serve: {
|
|
27
35
|
<E, R>(effect: Effect.Effect<HttpServerResponse, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>;
|
|
28
36
|
<E, R, App extends Effect.Effect<HttpServerResponse, any, any>>(effect: Effect.Effect<HttpServerResponse, E, R>, middleware: Middleware.HttpMiddleware.Applied<App, E, R>): Effect.Effect<void, never, Exclude<R, HttpServerRequest> | Scope.Scope>;
|
|
@@ -30,44 +38,76 @@ export declare const make: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMe
|
|
|
30
38
|
readonly address: HttpServer.Address;
|
|
31
39
|
}, ServeError, Scope.Scope>;
|
|
32
40
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
41
|
+
* Creates a Node `request` event handler for an Effect HTTP application,
|
|
42
|
+
* injecting a `HttpServerRequest` and interrupting the request fiber if the
|
|
43
|
+
* client closes the response before it finishes.
|
|
44
|
+
*
|
|
45
|
+
* @category handlers
|
|
46
|
+
* @since 4.0.0
|
|
35
47
|
*/
|
|
36
48
|
export declare const makeHandler: <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
|
|
37
49
|
readonly scope: Scope.Scope;
|
|
38
50
|
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
|
|
39
51
|
}) => Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>;
|
|
40
52
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
53
|
+
* Creates a Node `upgrade` event handler for an Effect HTTP application,
|
|
54
|
+
* exposing the upgraded WebSocket as the request's `upgrade` effect and
|
|
55
|
+
* interrupting the request fiber when the socket closes early.
|
|
56
|
+
*
|
|
57
|
+
* @category handlers
|
|
58
|
+
* @since 4.0.0
|
|
43
59
|
*/
|
|
44
60
|
export declare const makeUpgradeHandler: <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(lazyWss: Effect.Effect<NodeWS.WebSocketServer>, httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
|
|
45
61
|
readonly scope: Scope.Scope;
|
|
46
62
|
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
|
|
47
63
|
}) => Effect.Effect<(nodeRequest: Http.IncomingMessage, socket: Duplex, head: Buffer) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>;
|
|
48
64
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* Provides an `HttpServer` by creating and managing a scoped Node
|
|
66
|
+
* `http.Server` with the supplied listen and shutdown options.
|
|
67
|
+
*
|
|
68
|
+
* @category layers
|
|
69
|
+
* @since 4.0.0
|
|
51
70
|
*/
|
|
52
|
-
export declare const layerServer: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>, options: Net.ListenOptions
|
|
71
|
+
export declare const layerServer: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>, options: Net.ListenOptions & {
|
|
72
|
+
readonly disablePreemptiveShutdown?: boolean | undefined;
|
|
73
|
+
readonly gracefulShutdownTimeout?: Duration.Input | undefined;
|
|
74
|
+
}) => Layer.Layer<HttpServer.HttpServer, ServeError>;
|
|
53
75
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
76
|
+
* Provides the Node HTTP support services used by `NodeHttpServer`, including
|
|
77
|
+
* the HTTP platform, ETag generator, and core Node platform services.
|
|
78
|
+
*
|
|
79
|
+
* @category layers
|
|
80
|
+
* @since 4.0.0
|
|
56
81
|
*/
|
|
57
82
|
export declare const layerHttpServices: Layer.Layer<NodeServices.NodeServices | HttpPlatform.HttpPlatform | Etag.Generator>;
|
|
58
83
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
84
|
+
* Provides a Node `HttpServer` together with the Node HTTP platform, ETag, and
|
|
85
|
+
* core platform services required to serve requests.
|
|
86
|
+
*
|
|
87
|
+
* @category layers
|
|
88
|
+
* @since 4.0.0
|
|
61
89
|
*/
|
|
62
|
-
export declare const layer: (evaluate: LazyArg<Http.Server>, options: Net.ListenOptions
|
|
90
|
+
export declare const layer: (evaluate: LazyArg<Http.Server>, options: Net.ListenOptions & {
|
|
91
|
+
readonly disablePreemptiveShutdown?: boolean | undefined;
|
|
92
|
+
readonly gracefulShutdownTimeout?: Duration.Input | undefined;
|
|
93
|
+
}) => Layer.Layer<HttpServer.HttpServer | NodeServices.NodeServices | HttpPlatform.HttpPlatform | Etag.Generator, ServeError>;
|
|
63
94
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
95
|
+
* Provides a Node `HttpServer` and HTTP support services, reading the listen
|
|
96
|
+
* and shutdown options from a `Config` value.
|
|
97
|
+
*
|
|
98
|
+
* @category layers
|
|
99
|
+
* @since 4.0.0
|
|
66
100
|
*/
|
|
67
|
-
export declare const layerConfig: (evaluate: LazyArg<Http.Server>, options: Config.Wrap<Net.ListenOptions
|
|
101
|
+
export declare const layerConfig: (evaluate: LazyArg<Http.Server>, options: Config.Wrap<Net.ListenOptions & {
|
|
102
|
+
readonly disablePreemptiveShutdown?: boolean | undefined;
|
|
103
|
+
readonly gracefulShutdownTimeout?: Duration.Input | undefined;
|
|
104
|
+
}>) => Layer.Layer<HttpServer.HttpServer | FileSystem.FileSystem | Path.Path | HttpPlatform.HttpPlatform | Etag.Generator, ServeError | Config.ConfigError>;
|
|
68
105
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
106
|
+
* Provides a test HTTP server listening on an ephemeral port together with a
|
|
107
|
+
* Fetch-backed `HttpClient` configured for server integration tests.
|
|
108
|
+
*
|
|
109
|
+
* @category testing
|
|
110
|
+
* @since 4.0.0
|
|
71
111
|
*/
|
|
72
112
|
export declare const layerTest: Layer.Layer<HttpServer.HttpServer | FileSystem.FileSystem | Path.Path | HttpPlatform.HttpPlatform | Etag.Generator | HttpClient, ServeError, never>;
|
|
73
113
|
//# sourceMappingURL=NodeHttpServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeHttpServer.d.ts","sourceR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K,CAAC,KAAK,CACZ,UAAU,CAAC,UAAU,GAAG,YAAY,CAAC,YAAY,GAAG,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,EAC9F,UAAU,CAKT,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,UAAU,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAC9B,SAAS,MAAM,CAAC,IAAI,CAClB,GAAG,CAAC,aAAa,GAAG;IAClB,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACxD,QAAQ,CAAC,uBAAuB,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;CAC9D,CACF,KACA,KAAK,CAAC,KAAK,CACZ,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,EACtG,UAAU,GAAG,MAAM,CAAC,WAAW,CAO9B,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,KAAK,CAC/B,UAAU,CAAC,UAAU,GACrB,UAAU,CAAC,UAAU,GACrB,IAAI,CAAC,IAAI,GACT,YAAY,CAAC,YAAY,GACzB,IAAI,CAAC,SAAS,GACd,UAAU,EACZ,UAAU,EACV,KAAK,CAQN,CAAA"}
|
package/dist/NodeHttpServer.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementation of the Effect `HttpServer`.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a supplied Node `http.Server` into Effect's
|
|
5
|
+
* platform-independent HTTP server service. It starts the server with Node
|
|
6
|
+
* `listen` options, converts `request` events into `HttpServerRequest` values,
|
|
7
|
+
* writes `HttpServerResponse` bodies through Node's `ServerResponse`, and
|
|
8
|
+
* handles `upgrade` events by exposing the upgraded socket through
|
|
9
|
+
* `HttpServerRequest.upgrade`. It also exports request and upgrade handler
|
|
10
|
+
* constructors plus layers for the server alone, HTTP support services, the
|
|
11
|
+
* combined server, configurable options, and tests.
|
|
12
|
+
*
|
|
13
|
+
* @since 4.0.0
|
|
3
14
|
*/
|
|
4
15
|
import * as Cause from "effect/Cause";
|
|
5
16
|
import * as Config from "effect/Config";
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Duration from "effect/Duration";
|
|
6
19
|
import * as Effect from "effect/Effect";
|
|
7
20
|
import * as Fiber from "effect/Fiber";
|
|
8
21
|
import { flow } from "effect/Function";
|
|
9
22
|
import * as Latch from "effect/Latch";
|
|
10
23
|
import * as Layer from "effect/Layer";
|
|
11
24
|
import * as Scope from "effect/Scope";
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
13
25
|
import * as Stream from "effect/Stream";
|
|
14
26
|
import * as Cookies from "effect/unstable/http/Cookies";
|
|
15
27
|
import * as Etag from "effect/unstable/http/Etag";
|
|
@@ -17,7 +29,7 @@ import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
|
|
17
29
|
import * as HttpEffect from "effect/unstable/http/HttpEffect";
|
|
18
30
|
import * as HttpIncomingMessage from "effect/unstable/http/HttpIncomingMessage";
|
|
19
31
|
import * as HttpServer from "effect/unstable/http/HttpServer";
|
|
20
|
-
import { causeResponse,
|
|
32
|
+
import { causeResponse, ClientAbort, HttpServerError, RequestParseError, ResponseError, ServeError } from "effect/unstable/http/HttpServerError";
|
|
21
33
|
import * as Request from "effect/unstable/http/HttpServerRequest";
|
|
22
34
|
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
|
23
35
|
import * as Socket from "effect/unstable/socket/Socket";
|
|
@@ -30,13 +42,17 @@ import * as NodeMultipart from "./NodeMultipart.js";
|
|
|
30
42
|
import * as NodeServices from "./NodeServices.js";
|
|
31
43
|
import { NodeWS } from "./NodeSocket.js";
|
|
32
44
|
/**
|
|
33
|
-
*
|
|
45
|
+
* Creates a scoped `HttpServer` from a Node `http.Server`, starts listening
|
|
46
|
+
* with the supplied options, registers request and upgrade handling, and closes
|
|
47
|
+
* the server during scope finalization with optional graceful-shutdown control.
|
|
48
|
+
*
|
|
34
49
|
* @category constructors
|
|
50
|
+
* @since 4.0.0
|
|
35
51
|
*/
|
|
36
52
|
export const make = /*#__PURE__*/Effect.fnUntraced(function* (evaluate, options) {
|
|
37
53
|
const scope = yield* Effect.scope;
|
|
38
54
|
const server = evaluate();
|
|
39
|
-
yield*
|
|
55
|
+
const shutdown = yield* Effect.callback(resume => {
|
|
40
56
|
if (!server.listening) {
|
|
41
57
|
return resume(Effect.void);
|
|
42
58
|
}
|
|
@@ -47,7 +63,12 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (evaluate, options)
|
|
|
47
63
|
resume(Effect.void);
|
|
48
64
|
}
|
|
49
65
|
});
|
|
50
|
-
}));
|
|
66
|
+
}).pipe(Effect.cached);
|
|
67
|
+
const preemptiveShutdown = options.disablePreemptiveShutdown ? Effect.void : Effect.timeoutOrElse(shutdown, {
|
|
68
|
+
duration: options.gracefulShutdownTimeout ?? Duration.seconds(20),
|
|
69
|
+
orElse: () => Effect.void
|
|
70
|
+
});
|
|
71
|
+
yield* Scope.addFinalizer(scope, shutdown);
|
|
51
72
|
yield* Effect.callback(resume => {
|
|
52
73
|
function onError(cause) {
|
|
53
74
|
resume(Effect.fail(new ServeError({
|
|
@@ -76,7 +97,8 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (evaluate, options)
|
|
|
76
97
|
port: address.port
|
|
77
98
|
},
|
|
78
99
|
serve: Effect.fnUntraced(function* (httpApp, middleware) {
|
|
79
|
-
const
|
|
100
|
+
const serveScope = yield* Effect.scope;
|
|
101
|
+
const scope = Scope.forkUnsafe(serveScope, "parallel");
|
|
80
102
|
const handler = yield* makeHandler(httpApp, {
|
|
81
103
|
middleware: middleware,
|
|
82
104
|
scope
|
|
@@ -85,62 +107,75 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (evaluate, options)
|
|
|
85
107
|
middleware: middleware,
|
|
86
108
|
scope
|
|
87
109
|
});
|
|
88
|
-
yield*
|
|
110
|
+
yield* Scope.addFinalizerExit(serveScope, () => {
|
|
89
111
|
server.off("request", handler);
|
|
90
112
|
server.off("upgrade", upgradeHandler);
|
|
91
|
-
|
|
113
|
+
return preemptiveShutdown;
|
|
114
|
+
});
|
|
92
115
|
server.on("request", handler);
|
|
93
116
|
server.on("upgrade", upgradeHandler);
|
|
94
117
|
})
|
|
95
118
|
});
|
|
96
119
|
});
|
|
97
120
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
121
|
+
* Creates a Node `request` event handler for an Effect HTTP application,
|
|
122
|
+
* injecting a `HttpServerRequest` and interrupting the request fiber if the
|
|
123
|
+
* client closes the response before it finishes.
|
|
124
|
+
*
|
|
125
|
+
* @category handlers
|
|
126
|
+
* @since 4.0.0
|
|
100
127
|
*/
|
|
101
128
|
export const makeHandler = (httpEffect, options) => {
|
|
102
129
|
const handled = HttpEffect.toHandled(httpEffect, handleResponse, options.middleware);
|
|
103
|
-
return Effect.
|
|
104
|
-
|
|
130
|
+
return Effect.withFiber(parent => {
|
|
131
|
+
const services = parent.context;
|
|
132
|
+
return Effect.succeed(function handler(nodeRequest, nodeResponse) {
|
|
105
133
|
const map = new Map(services.mapUnsafe);
|
|
106
134
|
map.set(HttpServerRequest.key, new ServerRequestImpl(nodeRequest, nodeResponse));
|
|
107
|
-
const fiber = Fiber.runIn(Effect.runForkWith(
|
|
135
|
+
const fiber = Fiber.runIn(Effect.runForkWith(Context.makeUnsafe(map))(handled), options.scope);
|
|
108
136
|
nodeResponse.on("close", () => {
|
|
109
137
|
if (!nodeResponse.writableEnded) {
|
|
110
|
-
fiber.interruptUnsafe(
|
|
138
|
+
fiber.interruptUnsafe(parent.id, ClientAbort.annotation);
|
|
111
139
|
}
|
|
112
140
|
});
|
|
113
|
-
};
|
|
141
|
+
});
|
|
114
142
|
});
|
|
115
143
|
};
|
|
116
144
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
145
|
+
* Creates a Node `upgrade` event handler for an Effect HTTP application,
|
|
146
|
+
* exposing the upgraded WebSocket as the request's `upgrade` effect and
|
|
147
|
+
* interrupting the request fiber when the socket closes early.
|
|
148
|
+
*
|
|
149
|
+
* @category handlers
|
|
150
|
+
* @since 4.0.0
|
|
119
151
|
*/
|
|
120
152
|
export const makeUpgradeHandler = (lazyWss, httpEffect, options) => {
|
|
121
153
|
const handledApp = HttpEffect.toHandled(httpEffect, handleResponse, options.middleware);
|
|
122
|
-
return Effect.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
nodeResponse_
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
return Effect.withFiber(parent => {
|
|
155
|
+
const services = parent.context;
|
|
156
|
+
return Effect.succeed(function handler(nodeRequest, socket, head) {
|
|
157
|
+
let nodeResponse_ = undefined;
|
|
158
|
+
const nodeResponse = () => {
|
|
159
|
+
if (nodeResponse_ === undefined) {
|
|
160
|
+
nodeResponse_ = new Http.ServerResponse(nodeRequest);
|
|
161
|
+
nodeResponse_.assignSocket(socket);
|
|
162
|
+
nodeResponse_.on("finish", () => {
|
|
163
|
+
socket.end();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return nodeResponse_;
|
|
167
|
+
};
|
|
168
|
+
const upgradeEffect = Socket.fromWebSocket(Effect.flatMap(lazyWss, wss => Effect.acquireRelease(Effect.callback(resume => wss.handleUpgrade(nodeRequest, socket, head, ws => {
|
|
169
|
+
resume(Effect.succeed(ws));
|
|
170
|
+
})), ws => Effect.sync(() => ws.close()))));
|
|
171
|
+
const map = new Map(services.mapUnsafe);
|
|
172
|
+
map.set(HttpServerRequest.key, new ServerRequestImpl(nodeRequest, nodeResponse, upgradeEffect));
|
|
173
|
+
const fiber = Fiber.runIn(Effect.runForkWith(Context.makeUnsafe(map))(handledApp), options.scope);
|
|
174
|
+
socket.on("close", () => {
|
|
175
|
+
if (!socket.writableEnded) {
|
|
176
|
+
fiber.interruptUnsafe(parent.id, ClientAbort.annotation);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
144
179
|
});
|
|
145
180
|
});
|
|
146
181
|
};
|
|
@@ -174,7 +209,7 @@ class ServerRequestImpl extends NodeHttpIncomingMessage {
|
|
|
174
209
|
return typeof this.response === "function" ? this.response() : this.response;
|
|
175
210
|
}
|
|
176
211
|
modify(options) {
|
|
177
|
-
return new ServerRequestImpl(this.source, this.response, this.upgradeEffect, options.url ?? this.url, options.headers ?? this.headersOverride, options.remoteAddress
|
|
212
|
+
return new ServerRequestImpl(this.source, this.response, this.upgradeEffect, options.url ?? this.url, options.headers ?? this.headersOverride, "remoteAddress" in options ? options.remoteAddress : this.remoteAddressOverride);
|
|
178
213
|
}
|
|
179
214
|
get originalUrl() {
|
|
180
215
|
return this.source.url;
|
|
@@ -217,28 +252,43 @@ class ServerRequestImpl extends NodeHttpIncomingMessage {
|
|
|
217
252
|
}
|
|
218
253
|
}
|
|
219
254
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
255
|
+
* Provides an `HttpServer` by creating and managing a scoped Node
|
|
256
|
+
* `http.Server` with the supplied listen and shutdown options.
|
|
257
|
+
*
|
|
258
|
+
* @category layers
|
|
259
|
+
* @since 4.0.0
|
|
222
260
|
*/
|
|
223
261
|
export const layerServer = /*#__PURE__*/flow(make, /*#__PURE__*/Layer.effect(HttpServer.HttpServer));
|
|
224
262
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
263
|
+
* Provides the Node HTTP support services used by `NodeHttpServer`, including
|
|
264
|
+
* the HTTP platform, ETag generator, and core Node platform services.
|
|
265
|
+
*
|
|
266
|
+
* @category layers
|
|
267
|
+
* @since 4.0.0
|
|
227
268
|
*/
|
|
228
269
|
export const layerHttpServices = /*#__PURE__*/Layer.mergeAll(NodeHttpPlatform.layer, Etag.layerWeak, NodeServices.layer);
|
|
229
270
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
271
|
+
* Provides a Node `HttpServer` together with the Node HTTP platform, ETag, and
|
|
272
|
+
* core platform services required to serve requests.
|
|
273
|
+
*
|
|
274
|
+
* @category layers
|
|
275
|
+
* @since 4.0.0
|
|
232
276
|
*/
|
|
233
277
|
export const layer = (evaluate, options) => Layer.mergeAll(layerServer(evaluate, options), layerHttpServices);
|
|
234
278
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
279
|
+
* Provides a Node `HttpServer` and HTTP support services, reading the listen
|
|
280
|
+
* and shutdown options from a `Config` value.
|
|
281
|
+
*
|
|
282
|
+
* @category layers
|
|
283
|
+
* @since 4.0.0
|
|
237
284
|
*/
|
|
238
|
-
export const layerConfig = (evaluate, options) => Layer.mergeAll(Layer.effect(HttpServer.HttpServer)(Effect.flatMap(Config.unwrap(options)
|
|
285
|
+
export const layerConfig = (evaluate, options) => Layer.mergeAll(Layer.effect(HttpServer.HttpServer)(Effect.flatMap(Config.unwrap(options), options => make(evaluate, options))), layerHttpServices);
|
|
239
286
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
287
|
+
* Provides a test HTTP server listening on an ephemeral port together with a
|
|
288
|
+
* Fetch-backed `HttpClient` configured for server integration tests.
|
|
289
|
+
*
|
|
290
|
+
* @category testing
|
|
291
|
+
* @since 4.0.0
|
|
242
292
|
*/
|
|
243
293
|
export const layerTest = /*#__PURE__*/HttpServer.layerTestClient.pipe(/*#__PURE__*/Layer.provide(/*#__PURE__*/Layer.fresh(FetchHttpClient.layer).pipe(/*#__PURE__*/Layer.provide(/*#__PURE__*/Layer.succeed(FetchHttpClient.RequestInit)({
|
|
244
294
|
keepalive: false
|