elit 3.6.6 → 3.6.8
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +20 -1
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -19
- package/dist/build.js +420 -330
- package/dist/build.mjs +420 -330
- package/dist/chokidar.cjs +219 -182
- package/dist/chokidar.d.ts +25 -10
- package/dist/chokidar.js +217 -182
- package/dist/chokidar.mjs +218 -183
- package/dist/cli.cjs +25197 -22128
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +26668 -23614
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +17 -245
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/contracts-_0p1-15U.d.ts +54 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -62
- package/dist/coverage.js +447 -484
- package/dist/coverage.mjs +447 -484
- package/dist/database.cjs +819 -828
- package/dist/database.d.ts +8 -24
- package/dist/database.js +818 -829
- package/dist/database.mjs +818 -829
- package/dist/desktop-auto-render.cjs +1700 -1523
- package/dist/desktop-auto-render.d.ts +4 -12
- package/dist/desktop-auto-render.js +1695 -1518
- package/dist/desktop-auto-render.mjs +1696 -1519
- package/dist/desktop.cjs +3 -1
- package/dist/desktop.d.ts +4 -1
- package/dist/desktop.js +1 -1
- package/dist/desktop.mjs +1 -1
- package/dist/dev-build.cjs +830 -0
- package/dist/dev-build.d.ts +53 -0
- package/dist/dev-build.js +3318 -0
- package/dist/dev-build.mjs +797 -0
- package/dist/dom.cjs +717 -591
- package/dist/dom.d.ts +2 -17
- package/dist/dom.js +714 -588
- package/dist/dom.mjs +716 -590
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -12
- package/dist/el.js +60 -52
- package/dist/el.mjs +60 -52
- package/dist/fs.cjs +72 -63
- package/dist/fs.d.ts +22 -19
- package/dist/fs.js +71 -62
- package/dist/fs.mjs +71 -62
- package/dist/hmr.cjs +40 -14
- package/dist/hmr.d.ts +11 -23
- package/dist/hmr.js +38 -14
- package/dist/hmr.mjs +38 -14
- package/dist/http.cjs +411 -140
- package/dist/http.d.ts +40 -112
- package/dist/http.js +409 -140
- package/dist/http.mjs +409 -140
- package/dist/https.cjs +716 -272
- package/dist/https.d.ts +46 -41
- package/dist/https.js +712 -270
- package/dist/https.mjs +714 -272
- package/dist/index.cjs +7502 -7691
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7486 -7677
- package/dist/index.mjs +7497 -7687
- package/dist/mime-types.cjs +10 -4
- package/dist/mime-types.d.ts +8 -11
- package/dist/mime-types.js +9 -3
- package/dist/mime-types.mjs +9 -3
- package/dist/native.cjs +8616 -8870
- package/dist/native.d.ts +7 -10
- package/dist/native.js +8682 -8936
- package/dist/native.mjs +8615 -8869
- package/dist/path.cjs +83 -77
- package/dist/path.d.ts +29 -29
- package/dist/path.js +82 -76
- package/dist/path.mjs +82 -76
- package/dist/pm-node-shared-listener-bootstrap.cjs +75 -0
- package/dist/pm.cjs +5267 -0
- package/dist/pm.d.ts +331 -0
- package/dist/pm.js +7575 -0
- package/dist/pm.mjs +5148 -0
- package/dist/preview-build.cjs +712 -0
- package/dist/preview-build.d.ts +59 -0
- package/dist/preview-build.js +3194 -0
- package/dist/preview-build.mjs +676 -0
- package/dist/render-context.cjs +13 -2
- package/dist/render-context.d.ts +9 -34
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -646
- package/dist/router.d.ts +8 -14
- package/dist/router.js +786 -645
- package/dist/router.mjs +786 -645
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3702 -2883
- package/dist/server.d.ts +47 -5
- package/dist/server.js +4007 -3165
- package/dist/server.mjs +3665 -2848
- package/dist/smtp-server.cjs +16 -3
- package/dist/smtp-server.d.ts +12 -26
- package/dist/smtp-server.js +55 -17
- package/dist/smtp-server.mjs +16 -3
- package/dist/state.cjs +768 -659
- package/dist/state.d.ts +11 -71
- package/dist/state.js +760 -651
- package/dist/state.mjs +767 -658
- package/dist/style.cjs +1011 -968
- package/dist/style.d.ts +13 -127
- package/dist/style.js +1009 -970
- package/dist/style.mjs +1011 -971
- package/dist/test-reporter.cjs +332 -316
- package/dist/test-reporter.d.ts +28 -33
- package/dist/test-reporter.js +328 -312
- package/dist/test-reporter.mjs +328 -312
- package/dist/test-runtime.cjs +927 -968
- package/dist/test-runtime.d.ts +24 -99
- package/dist/test-runtime.js +922 -965
- package/dist/test-runtime.mjs +922 -965
- package/dist/test.cjs +4428 -4273
- package/dist/test.d.ts +2 -8
- package/dist/test.js +4307 -4154
- package/dist/test.mjs +4419 -4267
- package/dist/types-BONVzPtp.d.ts +59 -0
- package/dist/types-BR4wMiVx.d.ts +32 -0
- package/dist/types-BayMVo_k.d.ts +278 -0
- package/dist/types-C4gKykuG.d.ts +23 -0
- package/dist/types-C70T-42Z.d.ts +64 -0
- package/dist/types-Ckj8md_j.d.ts +84 -0
- package/dist/types-CpjQTAkX.d.ts +24 -0
- package/dist/types-D0LjrYjS.d.ts +14 -0
- package/dist/types-DPOgoGs-.d.ts +81 -0
- package/dist/types-fiLday0L.d.ts +199 -0
- package/dist/types.d.ts +54 -237
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -7
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-BLBEAnhp.d.ts +119 -0
- package/dist/ws.cjs +129 -108
- package/dist/ws.d.ts +21 -131
- package/dist/ws.js +128 -109
- package/dist/ws.mjs +128 -109
- package/dist/wss.cjs +938 -512
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +932 -508
- package/dist/wss.mjs +936 -512
- package/package.json +18 -6
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-uMQvZAll.d.ts +0 -458
package/dist/https.js
CHANGED
|
@@ -27,41 +27,78 @@
|
|
|
27
27
|
};
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
31
|
-
var runtime, isNode, isBun, isDeno;
|
|
32
|
-
var init_runtime = __esm({
|
|
33
|
-
"src/runtime.ts"() {
|
|
34
|
-
"use strict";
|
|
35
|
-
runtime = (() => {
|
|
36
|
-
if (typeof Deno !== "undefined") return "deno";
|
|
37
|
-
if (typeof Bun !== "undefined") return "bun";
|
|
38
|
-
return "node";
|
|
39
|
-
})();
|
|
40
|
-
isNode = runtime === "node";
|
|
41
|
-
isBun = runtime === "bun";
|
|
42
|
-
isDeno = runtime === "deno";
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// src/http.ts
|
|
47
|
-
var http_exports = {};
|
|
48
|
-
__export(http_exports, {
|
|
49
|
-
Agent: () => Agent,
|
|
50
|
-
ClientRequest: () => ClientRequest,
|
|
51
|
-
IncomingMessage: () => IncomingMessage,
|
|
52
|
-
METHODS: () => METHODS,
|
|
53
|
-
STATUS_CODES: () => STATUS_CODES,
|
|
54
|
-
Server: () => Server,
|
|
55
|
-
ServerResponse: () => ServerResponse,
|
|
56
|
-
createServer: () => createServer,
|
|
57
|
-
default: () => http_default,
|
|
58
|
-
get: () => get,
|
|
59
|
-
getRuntime: () => getRuntime,
|
|
60
|
-
request: () => request
|
|
61
|
-
});
|
|
30
|
+
// src/server/http/utils.ts
|
|
62
31
|
function queueCallback(callback) {
|
|
63
32
|
if (callback) queueMicrotask(callback);
|
|
64
33
|
}
|
|
34
|
+
function getRequestPath(url) {
|
|
35
|
+
if (!url) return "";
|
|
36
|
+
try {
|
|
37
|
+
const urlObj = new URL(url);
|
|
38
|
+
return urlObj.pathname + urlObj.search;
|
|
39
|
+
} catch {
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function headersToRecord(headers) {
|
|
44
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
45
|
+
headers.forEach((value, key) => {
|
|
46
|
+
result[key] = value;
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function headersToRawHeaders(headers) {
|
|
51
|
+
const rawHeaders = [];
|
|
52
|
+
headers.forEach((value, key) => {
|
|
53
|
+
rawHeaders.push(key, value);
|
|
54
|
+
});
|
|
55
|
+
return rawHeaders;
|
|
56
|
+
}
|
|
57
|
+
function normalizeRequestBodyChunk(chunk, encoding = "utf8") {
|
|
58
|
+
if (typeof chunk === "string") {
|
|
59
|
+
if (encoding !== "utf8" && typeof Buffer !== "undefined") {
|
|
60
|
+
return Buffer.from(chunk, encoding);
|
|
61
|
+
}
|
|
62
|
+
return chunk;
|
|
63
|
+
}
|
|
64
|
+
if (chunk instanceof Uint8Array) {
|
|
65
|
+
return chunk;
|
|
66
|
+
}
|
|
67
|
+
if (chunk instanceof ArrayBuffer) {
|
|
68
|
+
return new Uint8Array(chunk);
|
|
69
|
+
}
|
|
70
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
71
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
72
|
+
}
|
|
73
|
+
return new TextEncoder().encode(String(chunk));
|
|
74
|
+
}
|
|
75
|
+
function buildRequestBody(chunks) {
|
|
76
|
+
if (chunks.length === 0) {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
if (chunks.length === 1) {
|
|
80
|
+
return chunks[0];
|
|
81
|
+
}
|
|
82
|
+
if (chunks.every((chunk) => typeof chunk === "string")) {
|
|
83
|
+
return chunks.join("");
|
|
84
|
+
}
|
|
85
|
+
const encoder = new TextEncoder();
|
|
86
|
+
const bodyParts = chunks.map((chunk) => typeof chunk === "string" ? encoder.encode(chunk) : chunk);
|
|
87
|
+
const totalLength = bodyParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
88
|
+
const body = new Uint8Array(totalLength);
|
|
89
|
+
let offset = 0;
|
|
90
|
+
for (const part of bodyParts) {
|
|
91
|
+
body.set(part, offset);
|
|
92
|
+
offset += part.byteLength;
|
|
93
|
+
}
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
function isFetchResponse(value) {
|
|
97
|
+
return typeof value?.status === "number" && typeof value?.statusText === "string" && typeof value?.headers?.forEach === "function";
|
|
98
|
+
}
|
|
99
|
+
function isNodeIncomingMessage(value) {
|
|
100
|
+
return typeof value?.on === "function" && typeof value?.headers === "object" && (typeof value?.httpVersion === "string" || value?.socket !== void 0);
|
|
101
|
+
}
|
|
65
102
|
function headersToInit(headers) {
|
|
66
103
|
const result = {};
|
|
67
104
|
for (const key in headers) {
|
|
@@ -86,69 +123,119 @@
|
|
|
86
123
|
server.emit("close");
|
|
87
124
|
if (callback) queueMicrotask(() => callback());
|
|
88
125
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const incomingMessage = new IncomingMessage(fetchRequest);
|
|
120
|
-
incomingMessage.statusCode = response.status;
|
|
121
|
-
incomingMessage.statusMessage = response.statusText;
|
|
122
|
-
if (callback) callback(incomingMessage);
|
|
123
|
-
req.emit("response", incomingMessage);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
req.emit("error", error);
|
|
126
|
+
var init_utils = __esm({
|
|
127
|
+
"src/server/http/utils.ts"() {
|
|
128
|
+
"use strict";
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// src/shares/runtime.ts
|
|
133
|
+
var runtime, isNode, isBun, isDeno;
|
|
134
|
+
var init_runtime = __esm({
|
|
135
|
+
"src/shares/runtime.ts"() {
|
|
136
|
+
"use strict";
|
|
137
|
+
runtime = (() => {
|
|
138
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
139
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
140
|
+
return "node";
|
|
141
|
+
})();
|
|
142
|
+
isNode = runtime === "node";
|
|
143
|
+
isBun = runtime === "bun";
|
|
144
|
+
isDeno = runtime === "deno";
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// src/server/http/agent.ts
|
|
149
|
+
var Agent2;
|
|
150
|
+
var init_agent = __esm({
|
|
151
|
+
"src/server/http/agent.ts"() {
|
|
152
|
+
"use strict";
|
|
153
|
+
Agent2 = class {
|
|
154
|
+
constructor(options) {
|
|
155
|
+
this.options = options;
|
|
126
156
|
}
|
|
127
|
-
}
|
|
157
|
+
};
|
|
128
158
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return runtime;
|
|
136
|
-
}
|
|
137
|
-
var import_node_events, http, https, METHODS, STATUS_CODES, IncomingMessage, ServerResponse, Server, ClientRequest, Agent, http_default;
|
|
138
|
-
var init_http = __esm({
|
|
139
|
-
"src/http.ts"() {
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// src/server/http/client-request.ts
|
|
162
|
+
var import_node_events2, ClientRequest2;
|
|
163
|
+
var init_client_request = __esm({
|
|
164
|
+
"src/server/http/client-request.ts"() {
|
|
140
165
|
"use strict";
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
http = __require("http");
|
|
149
|
-
https = __require("https");
|
|
166
|
+
import_node_events2 = __require("events");
|
|
167
|
+
init_utils();
|
|
168
|
+
ClientRequest2 = class extends import_node_events2.EventEmitter {
|
|
169
|
+
constructor(_url, _options = {}) {
|
|
170
|
+
super();
|
|
171
|
+
this._bodyChunks = [];
|
|
172
|
+
this._ended = false;
|
|
150
173
|
}
|
|
151
|
-
|
|
174
|
+
_setNativeRequest(nativeRequest) {
|
|
175
|
+
this._nativeRequest = nativeRequest;
|
|
176
|
+
}
|
|
177
|
+
_setExecutor(executor) {
|
|
178
|
+
this._executor = executor;
|
|
179
|
+
}
|
|
180
|
+
write(chunk, encoding, callback) {
|
|
181
|
+
if (this._ended) {
|
|
182
|
+
throw new Error("Cannot write after end");
|
|
183
|
+
}
|
|
184
|
+
if (typeof encoding === "function") {
|
|
185
|
+
callback = encoding;
|
|
186
|
+
encoding = void 0;
|
|
187
|
+
}
|
|
188
|
+
if (this._nativeRequest) {
|
|
189
|
+
const actualEncoding2 = typeof encoding === "string" ? encoding : void 0;
|
|
190
|
+
return this._nativeRequest.write(chunk, actualEncoding2, callback);
|
|
191
|
+
}
|
|
192
|
+
const actualEncoding = typeof encoding === "string" ? encoding : "utf8";
|
|
193
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, actualEncoding));
|
|
194
|
+
queueCallback(callback);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
end(chunk, encoding, callback) {
|
|
198
|
+
if (typeof chunk === "function") {
|
|
199
|
+
callback = chunk;
|
|
200
|
+
chunk = void 0;
|
|
201
|
+
encoding = void 0;
|
|
202
|
+
} else if (typeof encoding === "function") {
|
|
203
|
+
callback = encoding;
|
|
204
|
+
encoding = void 0;
|
|
205
|
+
}
|
|
206
|
+
if (this._ended) {
|
|
207
|
+
queueCallback(callback);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this._ended = true;
|
|
211
|
+
if (this._nativeRequest) {
|
|
212
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
213
|
+
if (chunk !== void 0) {
|
|
214
|
+
this._nativeRequest.end(chunk, actualEncoding, callback);
|
|
215
|
+
} else {
|
|
216
|
+
this._nativeRequest.end(callback);
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (chunk !== void 0) {
|
|
221
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
222
|
+
}
|
|
223
|
+
const executor = this._executor;
|
|
224
|
+
const body = buildRequestBody(this._bodyChunks);
|
|
225
|
+
if (executor) {
|
|
226
|
+
Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
|
|
227
|
+
}
|
|
228
|
+
queueCallback(callback);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// src/server/http/constants.ts
|
|
235
|
+
var METHODS, STATUS_CODES;
|
|
236
|
+
var init_constants = __esm({
|
|
237
|
+
"src/server/http/constants.ts"() {
|
|
238
|
+
"use strict";
|
|
152
239
|
METHODS = [
|
|
153
240
|
"GET",
|
|
154
241
|
"POST",
|
|
@@ -216,13 +303,30 @@
|
|
|
216
303
|
510: "Not Extended",
|
|
217
304
|
511: "Network Authentication Required"
|
|
218
305
|
};
|
|
219
|
-
|
|
220
|
-
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// src/server/http/incoming-message.ts
|
|
310
|
+
var import_node_events3, IncomingMessage;
|
|
311
|
+
var init_incoming_message = __esm({
|
|
312
|
+
"src/server/http/incoming-message.ts"() {
|
|
313
|
+
"use strict";
|
|
314
|
+
import_node_events3 = __require("events");
|
|
315
|
+
init_utils();
|
|
316
|
+
IncomingMessage = class extends import_node_events3.EventEmitter {
|
|
317
|
+
constructor(req, requestMethod) {
|
|
221
318
|
super();
|
|
222
319
|
this.httpVersion = "1.1";
|
|
223
320
|
this.rawHeaders = [];
|
|
224
321
|
this._req = req;
|
|
225
|
-
if (
|
|
322
|
+
if (isFetchResponse(req)) {
|
|
323
|
+
this.method = requestMethod || "GET";
|
|
324
|
+
this.url = getRequestPath(req.url);
|
|
325
|
+
this.headers = headersToRecord(req.headers);
|
|
326
|
+
this.statusCode = req.status;
|
|
327
|
+
this.statusMessage = req.statusText;
|
|
328
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
329
|
+
} else if (isNodeIncomingMessage(req)) {
|
|
226
330
|
this.method = req.method;
|
|
227
331
|
this.url = req.url;
|
|
228
332
|
this.headers = req.headers;
|
|
@@ -233,14 +337,13 @@
|
|
|
233
337
|
this.socket = req.socket;
|
|
234
338
|
} else {
|
|
235
339
|
this.method = req.method;
|
|
236
|
-
|
|
237
|
-
this.
|
|
238
|
-
this.
|
|
239
|
-
this.rawHeaders = [];
|
|
340
|
+
this.url = getRequestPath(req.url);
|
|
341
|
+
this.headers = headersToRecord(req.headers);
|
|
342
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
240
343
|
}
|
|
241
344
|
}
|
|
242
345
|
async text() {
|
|
243
|
-
if (
|
|
346
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
244
347
|
return new Promise((resolve, reject) => {
|
|
245
348
|
const chunks = [];
|
|
246
349
|
this._req.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -251,14 +354,92 @@
|
|
|
251
354
|
return this._req.text();
|
|
252
355
|
}
|
|
253
356
|
async json() {
|
|
254
|
-
if (
|
|
357
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
255
358
|
const text = await this.text();
|
|
256
359
|
return JSON.parse(text);
|
|
257
360
|
}
|
|
258
361
|
return this._req.json();
|
|
259
362
|
}
|
|
260
363
|
};
|
|
261
|
-
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// src/server/http/node-modules.ts
|
|
368
|
+
var http, https;
|
|
369
|
+
var init_node_modules = __esm({
|
|
370
|
+
"src/server/http/node-modules.ts"() {
|
|
371
|
+
"use strict";
|
|
372
|
+
init_runtime();
|
|
373
|
+
if (isNode && typeof process !== "undefined") {
|
|
374
|
+
try {
|
|
375
|
+
http = __require("http");
|
|
376
|
+
https = __require("https");
|
|
377
|
+
} catch {
|
|
378
|
+
http = __require("http");
|
|
379
|
+
https = __require("https");
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// src/server/http/request-api.ts
|
|
386
|
+
function request(url, options, callback) {
|
|
387
|
+
const urlString = typeof url === "string" ? url : url.toString();
|
|
388
|
+
const req = new ClientRequest2(urlString, options);
|
|
389
|
+
if (isNode) {
|
|
390
|
+
const urlObj = new URL(urlString);
|
|
391
|
+
const client = urlObj.protocol === "https:" ? https : http;
|
|
392
|
+
const nodeReq = client.request(urlString, {
|
|
393
|
+
method: options?.method || "GET",
|
|
394
|
+
headers: options?.headers,
|
|
395
|
+
timeout: options?.timeout,
|
|
396
|
+
signal: options?.signal
|
|
397
|
+
}, (res) => {
|
|
398
|
+
const incomingMessage = new IncomingMessage(res);
|
|
399
|
+
if (callback) callback(incomingMessage);
|
|
400
|
+
req.emit("response", incomingMessage);
|
|
401
|
+
});
|
|
402
|
+
req._setNativeRequest(nodeReq);
|
|
403
|
+
nodeReq.on("error", (error) => req.emit("error", error));
|
|
404
|
+
} else {
|
|
405
|
+
req._setExecutor(async (body) => {
|
|
406
|
+
const response = await fetch(urlString, {
|
|
407
|
+
method: options?.method || "GET",
|
|
408
|
+
headers: options?.headers,
|
|
409
|
+
body,
|
|
410
|
+
signal: options?.signal
|
|
411
|
+
});
|
|
412
|
+
const incomingMessage = new IncomingMessage(response, options?.method || "GET");
|
|
413
|
+
if (callback) callback(incomingMessage);
|
|
414
|
+
req.emit("response", incomingMessage);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return req;
|
|
418
|
+
}
|
|
419
|
+
function get(url, options, callback) {
|
|
420
|
+
const req = request(url, { ...options, method: "GET" }, callback);
|
|
421
|
+
req.end();
|
|
422
|
+
return req;
|
|
423
|
+
}
|
|
424
|
+
var init_request_api = __esm({
|
|
425
|
+
"src/server/http/request-api.ts"() {
|
|
426
|
+
"use strict";
|
|
427
|
+
init_runtime();
|
|
428
|
+
init_client_request();
|
|
429
|
+
init_incoming_message();
|
|
430
|
+
init_node_modules();
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// src/server/http/response.ts
|
|
435
|
+
var import_node_events4, ServerResponse;
|
|
436
|
+
var init_response = __esm({
|
|
437
|
+
"src/server/http/response.ts"() {
|
|
438
|
+
"use strict";
|
|
439
|
+
import_node_events4 = __require("events");
|
|
440
|
+
init_runtime();
|
|
441
|
+
init_utils();
|
|
442
|
+
ServerResponse = class extends import_node_events4.EventEmitter {
|
|
262
443
|
constructor(_req, nodeRes) {
|
|
263
444
|
super();
|
|
264
445
|
this.statusCode = 200;
|
|
@@ -391,7 +572,6 @@
|
|
|
391
572
|
_setResolver(resolve) {
|
|
392
573
|
this._resolve = resolve;
|
|
393
574
|
}
|
|
394
|
-
// Express.js-like methods
|
|
395
575
|
json(data, statusCode = 200) {
|
|
396
576
|
if (!this.headersSent) {
|
|
397
577
|
this.setHeader("Content-Type", "application/json");
|
|
@@ -415,7 +595,36 @@
|
|
|
415
595
|
return this;
|
|
416
596
|
}
|
|
417
597
|
};
|
|
418
|
-
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// src/server/http/runtime.ts
|
|
602
|
+
function getRuntime() {
|
|
603
|
+
return runtime;
|
|
604
|
+
}
|
|
605
|
+
var init_runtime2 = __esm({
|
|
606
|
+
"src/server/http/runtime.ts"() {
|
|
607
|
+
"use strict";
|
|
608
|
+
init_runtime();
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
// src/server/http/server-runtime.ts
|
|
613
|
+
function createServer(arg1, arg2) {
|
|
614
|
+
const requestListener = typeof arg1 === "function" ? arg1 : arg2;
|
|
615
|
+
return new Server(requestListener);
|
|
616
|
+
}
|
|
617
|
+
var import_node_events5, Server;
|
|
618
|
+
var init_server_runtime = __esm({
|
|
619
|
+
"src/server/http/server-runtime.ts"() {
|
|
620
|
+
"use strict";
|
|
621
|
+
import_node_events5 = __require("events");
|
|
622
|
+
init_runtime();
|
|
623
|
+
init_node_modules();
|
|
624
|
+
init_incoming_message();
|
|
625
|
+
init_response();
|
|
626
|
+
init_utils();
|
|
627
|
+
Server = class extends import_node_events5.EventEmitter {
|
|
419
628
|
constructor(requestListener) {
|
|
420
629
|
super();
|
|
421
630
|
this._bunWebSocketServers = /* @__PURE__ */ new Set();
|
|
@@ -428,9 +637,28 @@
|
|
|
428
637
|
unregisterWebSocketServer(wsServer) {
|
|
429
638
|
this._bunWebSocketServers.delete(wsServer);
|
|
430
639
|
}
|
|
640
|
+
resolvePmInheritedFd(explicitPort, explicitFd) {
|
|
641
|
+
if (typeof explicitFd === "number" && Number.isInteger(explicitFd) && explicitFd >= 0) {
|
|
642
|
+
return explicitFd;
|
|
643
|
+
}
|
|
644
|
+
const fdValue = process.env.ELIT_PM_LISTEN_FD;
|
|
645
|
+
if (!fdValue) {
|
|
646
|
+
return void 0;
|
|
647
|
+
}
|
|
648
|
+
const parsedFd = Number.parseInt(fdValue, 10);
|
|
649
|
+
if (!Number.isInteger(parsedFd) || parsedFd < 0) {
|
|
650
|
+
return void 0;
|
|
651
|
+
}
|
|
652
|
+
const publicPort = Number.parseInt(process.env.ELIT_PM_PUBLIC_PORT ?? process.env.ELIT_PM_PORT ?? "", 10);
|
|
653
|
+
if (Number.isInteger(explicitPort) && Number.isInteger(publicPort) && explicitPort !== publicPort) {
|
|
654
|
+
return void 0;
|
|
655
|
+
}
|
|
656
|
+
return parsedFd;
|
|
657
|
+
}
|
|
431
658
|
listen(...args) {
|
|
432
659
|
let port = 3e3;
|
|
433
660
|
let hostname = "0.0.0.0";
|
|
661
|
+
let fd;
|
|
434
662
|
let callback;
|
|
435
663
|
const firstArg = args[0];
|
|
436
664
|
if (typeof firstArg === "number") {
|
|
@@ -445,8 +673,10 @@
|
|
|
445
673
|
} else if (firstArg && typeof firstArg === "object") {
|
|
446
674
|
port = firstArg.port || 3e3;
|
|
447
675
|
hostname = firstArg.hostname || "0.0.0.0";
|
|
676
|
+
fd = typeof firstArg.fd === "number" ? firstArg.fd : void 0;
|
|
448
677
|
callback = args[1];
|
|
449
678
|
}
|
|
679
|
+
fd = this.resolvePmInheritedFd(firstArg && typeof firstArg === "object" ? firstArg.port : port, fd);
|
|
450
680
|
const self = this;
|
|
451
681
|
if (isNode) {
|
|
452
682
|
this.nativeServer = http.createServer((req, res) => {
|
|
@@ -461,11 +691,19 @@
|
|
|
461
691
|
this.nativeServer.on("upgrade", (req, socket, head) => {
|
|
462
692
|
self.emit("upgrade", req, socket, head);
|
|
463
693
|
});
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
694
|
+
if (fd !== void 0) {
|
|
695
|
+
this.nativeServer.listen({ fd, exclusive: false }, () => {
|
|
696
|
+
this._listening = true;
|
|
697
|
+
this.emit("listening");
|
|
698
|
+
if (callback) callback();
|
|
699
|
+
});
|
|
700
|
+
} else {
|
|
701
|
+
this.nativeServer.listen(port, hostname, () => {
|
|
702
|
+
this._listening = true;
|
|
703
|
+
this.emit("listening");
|
|
704
|
+
if (callback) callback();
|
|
705
|
+
});
|
|
706
|
+
}
|
|
469
707
|
this.nativeServer.on("error", (err) => this.emit("error", err));
|
|
470
708
|
this.nativeServer.on("close", () => {
|
|
471
709
|
this._listening = false;
|
|
@@ -490,6 +728,8 @@
|
|
|
490
728
|
const urlObj = new URL(req.url);
|
|
491
729
|
const pathname = urlObj.pathname;
|
|
492
730
|
const requestUrl = urlObj.pathname + urlObj.search;
|
|
731
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
732
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
493
733
|
const upgradeHeader = req.headers.get("upgrade");
|
|
494
734
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
495
735
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
@@ -526,9 +766,9 @@
|
|
|
526
766
|
const incomingMessage = {
|
|
527
767
|
method: req.method,
|
|
528
768
|
url: requestUrl,
|
|
529
|
-
headers:
|
|
769
|
+
headers: incomingHeaders,
|
|
530
770
|
httpVersion: "1.1",
|
|
531
|
-
rawHeaders
|
|
771
|
+
rawHeaders,
|
|
532
772
|
_req: req,
|
|
533
773
|
text: () => req.text(),
|
|
534
774
|
json: () => req.json()
|
|
@@ -582,57 +822,148 @@
|
|
|
582
822
|
this.writeHead(statusCode);
|
|
583
823
|
}
|
|
584
824
|
responseReady = true;
|
|
585
|
-
return this;
|
|
586
825
|
}
|
|
587
826
|
};
|
|
588
827
|
if (self.requestListener) {
|
|
589
828
|
self.requestListener(incomingMessage, serverResponse);
|
|
829
|
+
} else {
|
|
830
|
+
self.emit("request", incomingMessage, serverResponse);
|
|
590
831
|
}
|
|
591
|
-
if (responseReady) {
|
|
592
|
-
|
|
593
|
-
status: statusCode,
|
|
594
|
-
statusText: statusMessage,
|
|
595
|
-
headers
|
|
596
|
-
});
|
|
832
|
+
if (!responseReady) {
|
|
833
|
+
serverResponse.end();
|
|
597
834
|
}
|
|
598
|
-
return new
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
resolve(new Response(body, {
|
|
604
|
-
status: statusCode,
|
|
605
|
-
statusText: statusMessage,
|
|
606
|
-
headers
|
|
607
|
-
}));
|
|
608
|
-
};
|
|
835
|
+
return new Response(body, {
|
|
836
|
+
status: statusCode,
|
|
837
|
+
statusText: statusMessage,
|
|
838
|
+
headers
|
|
609
839
|
});
|
|
610
840
|
},
|
|
611
|
-
error:
|
|
841
|
+
error: (err) => {
|
|
842
|
+
this.emit("error", err);
|
|
843
|
+
return createErrorResponse();
|
|
844
|
+
}
|
|
612
845
|
});
|
|
846
|
+
this._listening = true;
|
|
613
847
|
emitListeningWithCallback(this, callback);
|
|
848
|
+
this.nativeServer.stop = this.nativeServer.stop || this.nativeServer.close;
|
|
849
|
+
this.nativeServer.close = this.nativeServer.close || this.nativeServer.stop;
|
|
850
|
+
this.nativeServer.on?.("close", () => {
|
|
851
|
+
this._listening = false;
|
|
852
|
+
this.emit("close");
|
|
853
|
+
});
|
|
614
854
|
} else if (isDeno) {
|
|
855
|
+
const server = this;
|
|
615
856
|
this.nativeServer = Deno.serve({
|
|
616
857
|
port,
|
|
617
|
-
hostname
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
858
|
+
hostname
|
|
859
|
+
}, async (req) => {
|
|
860
|
+
const urlObj = new URL(req.url);
|
|
861
|
+
const requestUrl = urlObj.pathname + urlObj.search;
|
|
862
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
863
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
864
|
+
const bodyChunks = [];
|
|
865
|
+
const responseHeaders = new Headers();
|
|
866
|
+
let statusCode = 200;
|
|
867
|
+
let statusText = "OK";
|
|
868
|
+
let responseClosed = false;
|
|
869
|
+
const incomingMessage = {
|
|
870
|
+
method: req.method,
|
|
871
|
+
url: requestUrl,
|
|
872
|
+
headers: incomingHeaders,
|
|
873
|
+
httpVersion: "1.1",
|
|
874
|
+
rawHeaders,
|
|
875
|
+
_req: req,
|
|
876
|
+
text: () => req.text(),
|
|
877
|
+
json: () => req.json()
|
|
878
|
+
};
|
|
879
|
+
const serverResponse = {
|
|
880
|
+
statusCode: 200,
|
|
881
|
+
statusMessage: "OK",
|
|
882
|
+
headersSent: false,
|
|
883
|
+
setHeader(name, value) {
|
|
884
|
+
responseHeaders.set(name, Array.isArray(value) ? value.join(", ") : String(value));
|
|
885
|
+
return this;
|
|
886
|
+
},
|
|
887
|
+
getHeader(name) {
|
|
888
|
+
return responseHeaders.get(name) ?? void 0;
|
|
889
|
+
},
|
|
890
|
+
getHeaders() {
|
|
891
|
+
const headers = {};
|
|
892
|
+
responseHeaders.forEach((value, key) => {
|
|
893
|
+
headers[key] = value;
|
|
894
|
+
});
|
|
895
|
+
return headers;
|
|
896
|
+
},
|
|
897
|
+
writeHead(status, arg2, arg3) {
|
|
898
|
+
statusCode = status;
|
|
899
|
+
this.statusCode = status;
|
|
900
|
+
this.headersSent = true;
|
|
901
|
+
if (typeof arg2 === "string") {
|
|
902
|
+
statusText = arg2;
|
|
903
|
+
this.statusMessage = arg2;
|
|
904
|
+
if (arg3) {
|
|
905
|
+
Object.entries(arg3).forEach(([key, value]) => {
|
|
906
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
} else if (arg2) {
|
|
910
|
+
Object.entries(arg2).forEach(([key, value]) => {
|
|
911
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
912
|
+
});
|
|
627
913
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
914
|
+
return this;
|
|
915
|
+
},
|
|
916
|
+
write(chunk) {
|
|
917
|
+
if (!this.headersSent) {
|
|
918
|
+
this.writeHead(statusCode);
|
|
919
|
+
}
|
|
920
|
+
if (typeof chunk === "string") {
|
|
921
|
+
bodyChunks.push(new TextEncoder().encode(chunk));
|
|
922
|
+
} else if (chunk instanceof Uint8Array) {
|
|
923
|
+
bodyChunks.push(chunk);
|
|
924
|
+
} else if (chunk !== void 0 && chunk !== null) {
|
|
925
|
+
bodyChunks.push(new TextEncoder().encode(String(chunk)));
|
|
926
|
+
}
|
|
927
|
+
return true;
|
|
928
|
+
},
|
|
929
|
+
end(chunk) {
|
|
930
|
+
if (chunk !== void 0) {
|
|
931
|
+
this.write(chunk);
|
|
932
|
+
}
|
|
933
|
+
if (!this.headersSent) {
|
|
934
|
+
this.writeHead(statusCode);
|
|
935
|
+
}
|
|
936
|
+
responseClosed = true;
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
if (server.requestListener) {
|
|
940
|
+
server.requestListener(incomingMessage, serverResponse);
|
|
941
|
+
} else {
|
|
942
|
+
server.emit("request", incomingMessage, serverResponse);
|
|
633
943
|
}
|
|
944
|
+
if (!responseClosed) {
|
|
945
|
+
serverResponse.end();
|
|
946
|
+
}
|
|
947
|
+
const body = bodyChunks.length === 0 ? void 0 : (() => {
|
|
948
|
+
const totalLength = bodyChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
949
|
+
const output = new ArrayBuffer(totalLength);
|
|
950
|
+
const combined = new Uint8Array(output);
|
|
951
|
+
let offset = 0;
|
|
952
|
+
for (const chunk of bodyChunks) {
|
|
953
|
+
combined.set(chunk, offset);
|
|
954
|
+
offset += chunk.length;
|
|
955
|
+
}
|
|
956
|
+
return output;
|
|
957
|
+
})();
|
|
958
|
+
return new Response(body, {
|
|
959
|
+
status: statusCode,
|
|
960
|
+
statusText,
|
|
961
|
+
headers: responseHeaders
|
|
962
|
+
});
|
|
634
963
|
});
|
|
964
|
+
this._listening = true;
|
|
635
965
|
emitListeningWithCallback(this, callback);
|
|
966
|
+
this.nativeServer.finished.then(() => closeAndEmit(this)).catch((err) => this.emit("error", err));
|
|
636
967
|
}
|
|
637
968
|
return this;
|
|
638
969
|
}
|
|
@@ -661,9 +992,11 @@
|
|
|
661
992
|
return createAddress(0, addr, "unix");
|
|
662
993
|
}
|
|
663
994
|
return addr;
|
|
664
|
-
}
|
|
995
|
+
}
|
|
996
|
+
if (isBun) {
|
|
665
997
|
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
666
|
-
}
|
|
998
|
+
}
|
|
999
|
+
if (isDeno) {
|
|
667
1000
|
const addr = this.nativeServer.addr;
|
|
668
1001
|
return createAddress(addr.port, addr.hostname);
|
|
669
1002
|
}
|
|
@@ -673,22 +1006,45 @@
|
|
|
673
1006
|
return this._listening;
|
|
674
1007
|
}
|
|
675
1008
|
};
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
// src/server/http/index.ts
|
|
1013
|
+
var http_exports = {};
|
|
1014
|
+
__export(http_exports, {
|
|
1015
|
+
Agent: () => Agent2,
|
|
1016
|
+
ClientRequest: () => ClientRequest2,
|
|
1017
|
+
IncomingMessage: () => IncomingMessage,
|
|
1018
|
+
METHODS: () => METHODS,
|
|
1019
|
+
STATUS_CODES: () => STATUS_CODES,
|
|
1020
|
+
Server: () => Server,
|
|
1021
|
+
ServerResponse: () => ServerResponse,
|
|
1022
|
+
createServer: () => createServer,
|
|
1023
|
+
default: () => http_default,
|
|
1024
|
+
get: () => get,
|
|
1025
|
+
getRuntime: () => getRuntime,
|
|
1026
|
+
request: () => request
|
|
1027
|
+
});
|
|
1028
|
+
var http_default;
|
|
1029
|
+
var init_http = __esm({
|
|
1030
|
+
"src/server/http/index.ts"() {
|
|
1031
|
+
"use strict";
|
|
1032
|
+
init_agent();
|
|
1033
|
+
init_client_request();
|
|
1034
|
+
init_constants();
|
|
1035
|
+
init_incoming_message();
|
|
1036
|
+
init_request_api();
|
|
1037
|
+
init_response();
|
|
1038
|
+
init_runtime2();
|
|
1039
|
+
init_server_runtime();
|
|
1040
|
+
init_agent();
|
|
1041
|
+
init_client_request();
|
|
1042
|
+
init_constants();
|
|
1043
|
+
init_incoming_message();
|
|
1044
|
+
init_request_api();
|
|
1045
|
+
init_response();
|
|
1046
|
+
init_runtime2();
|
|
1047
|
+
init_server_runtime();
|
|
692
1048
|
http_default = {
|
|
693
1049
|
createServer,
|
|
694
1050
|
request,
|
|
@@ -696,8 +1052,8 @@
|
|
|
696
1052
|
Server,
|
|
697
1053
|
IncomingMessage,
|
|
698
1054
|
ServerResponse,
|
|
699
|
-
Agent,
|
|
700
|
-
ClientRequest,
|
|
1055
|
+
Agent: Agent2,
|
|
1056
|
+
ClientRequest: ClientRequest2,
|
|
701
1057
|
METHODS,
|
|
702
1058
|
STATUS_CODES,
|
|
703
1059
|
getRuntime
|
|
@@ -705,28 +1061,83 @@
|
|
|
705
1061
|
}
|
|
706
1062
|
});
|
|
707
1063
|
|
|
708
|
-
// src/https.ts
|
|
709
|
-
var
|
|
1064
|
+
// src/server/https/agent.ts
|
|
1065
|
+
var Agent = class {
|
|
1066
|
+
constructor(options) {
|
|
1067
|
+
this.options = options;
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1071
|
+
// src/server/https/client-request.ts
|
|
1072
|
+
var import_node_events = __require("events");
|
|
1073
|
+
init_utils();
|
|
1074
|
+
var ClientRequest = class extends import_node_events.EventEmitter {
|
|
1075
|
+
constructor(_url, _options = {}) {
|
|
1076
|
+
super();
|
|
1077
|
+
this._bodyChunks = [];
|
|
1078
|
+
this._ended = false;
|
|
1079
|
+
}
|
|
1080
|
+
_setNativeRequest(nativeRequest) {
|
|
1081
|
+
this._nativeRequest = nativeRequest;
|
|
1082
|
+
}
|
|
1083
|
+
_setExecutor(executor) {
|
|
1084
|
+
this._executor = executor;
|
|
1085
|
+
}
|
|
1086
|
+
write(chunk, encoding, callback) {
|
|
1087
|
+
if (this._ended) {
|
|
1088
|
+
throw new Error("Cannot write after end");
|
|
1089
|
+
}
|
|
1090
|
+
if (typeof encoding === "function") {
|
|
1091
|
+
callback = encoding;
|
|
1092
|
+
encoding = void 0;
|
|
1093
|
+
}
|
|
1094
|
+
if (this._nativeRequest) {
|
|
1095
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
1096
|
+
return this._nativeRequest.write(chunk, actualEncoding, callback);
|
|
1097
|
+
}
|
|
1098
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
1099
|
+
queueCallback(callback);
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
end(chunk, encoding, callback) {
|
|
1103
|
+
if (typeof chunk === "function") {
|
|
1104
|
+
callback = chunk;
|
|
1105
|
+
chunk = void 0;
|
|
1106
|
+
encoding = void 0;
|
|
1107
|
+
} else if (typeof encoding === "function") {
|
|
1108
|
+
callback = encoding;
|
|
1109
|
+
encoding = void 0;
|
|
1110
|
+
}
|
|
1111
|
+
if (this._ended) {
|
|
1112
|
+
queueCallback(callback);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
this._ended = true;
|
|
1116
|
+
if (this._nativeRequest) {
|
|
1117
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
1118
|
+
if (chunk !== void 0) {
|
|
1119
|
+
this._nativeRequest.end(chunk, actualEncoding, callback);
|
|
1120
|
+
} else {
|
|
1121
|
+
this._nativeRequest.end(callback);
|
|
1122
|
+
}
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (chunk !== void 0) {
|
|
1126
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
1127
|
+
}
|
|
1128
|
+
const executor = this._executor;
|
|
1129
|
+
const body = buildRequestBody(this._bodyChunks);
|
|
1130
|
+
if (executor) {
|
|
1131
|
+
Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
|
|
1132
|
+
}
|
|
1133
|
+
queueCallback(callback);
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
// src/server/https/request-api.ts
|
|
710
1138
|
init_runtime();
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
function createErrorResponse2() {
|
|
715
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
716
|
-
}
|
|
717
|
-
function createAddress2(port, address, family = "IPv4") {
|
|
718
|
-
return { port, family, address };
|
|
719
|
-
}
|
|
720
|
-
function emitListeningWithCallback2(server, callback) {
|
|
721
|
-
server._listening = true;
|
|
722
|
-
server.emit("listening");
|
|
723
|
-
queueCallback2(callback);
|
|
724
|
-
}
|
|
725
|
-
function closeAndEmit2(server, callback) {
|
|
726
|
-
server._listening = false;
|
|
727
|
-
server.emit("close");
|
|
728
|
-
if (callback) queueMicrotask(() => callback());
|
|
729
|
-
}
|
|
1139
|
+
|
|
1140
|
+
// src/server/https/http-classes.ts
|
|
730
1141
|
function loadHttpClasses() {
|
|
731
1142
|
const httpModule = (init_http(), __toCommonJS(http_exports));
|
|
732
1143
|
return {
|
|
@@ -734,17 +1145,97 @@
|
|
|
734
1145
|
ServerResponse: httpModule.ServerResponse
|
|
735
1146
|
};
|
|
736
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
// src/server/https/node-modules.ts
|
|
1150
|
+
init_runtime();
|
|
737
1151
|
var https2;
|
|
738
|
-
|
|
739
|
-
|
|
1152
|
+
if (isNode && typeof process !== "undefined") {
|
|
1153
|
+
try {
|
|
1154
|
+
https2 = __require("https");
|
|
1155
|
+
} catch {
|
|
1156
|
+
https2 = __require("https");
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/server/https/request-api.ts
|
|
1161
|
+
function request2(url, options, callback) {
|
|
1162
|
+
const urlString = typeof url === "string" ? url : url.toString();
|
|
1163
|
+
const req = new ClientRequest(urlString, options);
|
|
1164
|
+
if (isNode) {
|
|
1165
|
+
const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
|
|
1166
|
+
const nodeReq = https2.request(urlString, {
|
|
1167
|
+
method: options?.method || "GET",
|
|
1168
|
+
headers: options?.headers,
|
|
1169
|
+
timeout: options?.timeout,
|
|
1170
|
+
signal: options?.signal
|
|
1171
|
+
}, (res) => {
|
|
1172
|
+
const incomingMessage = new IncomingMessage2(res);
|
|
1173
|
+
if (callback) callback(incomingMessage);
|
|
1174
|
+
req.emit("response", incomingMessage);
|
|
1175
|
+
});
|
|
1176
|
+
req._setNativeRequest(nodeReq);
|
|
1177
|
+
nodeReq.on("error", (error) => req.emit("error", error));
|
|
1178
|
+
} else {
|
|
1179
|
+
const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
|
|
1180
|
+
req._setExecutor(async (body) => {
|
|
1181
|
+
const response = await fetch(urlString, {
|
|
1182
|
+
method: options?.method || "GET",
|
|
1183
|
+
headers: options?.headers,
|
|
1184
|
+
body,
|
|
1185
|
+
signal: options?.signal
|
|
1186
|
+
});
|
|
1187
|
+
const incomingMessage = new IncomingMessage2(response, options?.method || "GET");
|
|
1188
|
+
if (callback) callback(incomingMessage);
|
|
1189
|
+
req.emit("response", incomingMessage);
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
return req;
|
|
1193
|
+
}
|
|
1194
|
+
function get2(url, options, callback) {
|
|
1195
|
+
const req = request2(url, { ...options, method: "GET" }, callback);
|
|
1196
|
+
req.end();
|
|
1197
|
+
return req;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// src/server/https/runtime.ts
|
|
1201
|
+
init_runtime();
|
|
1202
|
+
function getRuntime2() {
|
|
1203
|
+
return runtime;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// src/server/https/server-runtime.ts
|
|
1207
|
+
var import_node_events6 = __require("events");
|
|
1208
|
+
init_runtime();
|
|
1209
|
+
init_utils();
|
|
1210
|
+
var Server2 = class extends import_node_events6.EventEmitter {
|
|
1211
|
+
constructor(options = {}, requestListener) {
|
|
740
1212
|
super();
|
|
741
1213
|
this._listening = false;
|
|
742
1214
|
this.options = options;
|
|
743
1215
|
this.requestListener = requestListener;
|
|
744
1216
|
}
|
|
1217
|
+
resolvePmInheritedFd(explicitPort, explicitFd) {
|
|
1218
|
+
if (typeof explicitFd === "number" && Number.isInteger(explicitFd) && explicitFd >= 0) {
|
|
1219
|
+
return explicitFd;
|
|
1220
|
+
}
|
|
1221
|
+
const fdValue = process.env.ELIT_PM_LISTEN_FD;
|
|
1222
|
+
if (!fdValue) {
|
|
1223
|
+
return void 0;
|
|
1224
|
+
}
|
|
1225
|
+
const parsedFd = Number.parseInt(fdValue, 10);
|
|
1226
|
+
if (!Number.isInteger(parsedFd) || parsedFd < 0) {
|
|
1227
|
+
return void 0;
|
|
1228
|
+
}
|
|
1229
|
+
const publicPort = Number.parseInt(process.env.ELIT_PM_PUBLIC_PORT ?? process.env.ELIT_PM_PORT ?? "", 10);
|
|
1230
|
+
if (Number.isInteger(explicitPort) && Number.isInteger(publicPort) && explicitPort !== publicPort) {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
return parsedFd;
|
|
1234
|
+
}
|
|
745
1235
|
listen(...args) {
|
|
746
1236
|
let port = 3e3;
|
|
747
1237
|
let hostname = "0.0.0.0";
|
|
1238
|
+
let fd;
|
|
748
1239
|
let callback;
|
|
749
1240
|
const firstArg = args[0];
|
|
750
1241
|
if (typeof firstArg === "number") {
|
|
@@ -759,12 +1250,13 @@
|
|
|
759
1250
|
} else if (firstArg && typeof firstArg === "object") {
|
|
760
1251
|
port = firstArg.port || 3e3;
|
|
761
1252
|
hostname = firstArg.hostname || "0.0.0.0";
|
|
1253
|
+
fd = typeof firstArg.fd === "number" ? firstArg.fd : void 0;
|
|
762
1254
|
callback = args[1];
|
|
763
1255
|
}
|
|
1256
|
+
fd = this.resolvePmInheritedFd(firstArg && typeof firstArg === "object" ? firstArg.port : port, fd);
|
|
764
1257
|
const self = this;
|
|
765
1258
|
if (isNode) {
|
|
766
1259
|
const { IncomingMessage: IncomingMessage2, ServerResponse: ServerResponse2 } = loadHttpClasses();
|
|
767
|
-
if (!https2) https2 = __require("https");
|
|
768
1260
|
this.nativeServer = https2.createServer(this.options, (req, res) => {
|
|
769
1261
|
const incomingMessage = new IncomingMessage2(req);
|
|
770
1262
|
const serverResponse = new ServerResponse2(incomingMessage, res);
|
|
@@ -774,11 +1266,19 @@
|
|
|
774
1266
|
self.emit("request", incomingMessage, serverResponse);
|
|
775
1267
|
}
|
|
776
1268
|
});
|
|
777
|
-
|
|
778
|
-
this.
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
1269
|
+
if (fd !== void 0) {
|
|
1270
|
+
this.nativeServer.listen({ fd, exclusive: false }, () => {
|
|
1271
|
+
this._listening = true;
|
|
1272
|
+
this.emit("listening");
|
|
1273
|
+
if (callback) callback();
|
|
1274
|
+
});
|
|
1275
|
+
} else {
|
|
1276
|
+
this.nativeServer.listen(port, hostname, () => {
|
|
1277
|
+
this._listening = true;
|
|
1278
|
+
this.emit("listening");
|
|
1279
|
+
if (callback) callback();
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
782
1282
|
this.nativeServer.on("error", (err) => this.emit("error", err));
|
|
783
1283
|
this.nativeServer.on("close", () => {
|
|
784
1284
|
this._listening = false;
|
|
@@ -803,7 +1303,7 @@
|
|
|
803
1303
|
},
|
|
804
1304
|
error: (error) => {
|
|
805
1305
|
this.emit("error", error);
|
|
806
|
-
return
|
|
1306
|
+
return createErrorResponse();
|
|
807
1307
|
}
|
|
808
1308
|
};
|
|
809
1309
|
if (this.options.key || this.options.cert) {
|
|
@@ -817,7 +1317,7 @@
|
|
|
817
1317
|
tlsOptions.tls = this.options.tls;
|
|
818
1318
|
}
|
|
819
1319
|
this.nativeServer = Bun.serve(tlsOptions);
|
|
820
|
-
|
|
1320
|
+
emitListeningWithCallback(this, callback);
|
|
821
1321
|
} else if (isDeno) {
|
|
822
1322
|
const { IncomingMessage: IncomingMessage2, ServerResponse: ServerResponse2 } = loadHttpClasses();
|
|
823
1323
|
const serveOptions = {
|
|
@@ -837,7 +1337,7 @@
|
|
|
837
1337
|
},
|
|
838
1338
|
onError: (error) => {
|
|
839
1339
|
this.emit("error", error);
|
|
840
|
-
return
|
|
1340
|
+
return createErrorResponse();
|
|
841
1341
|
}
|
|
842
1342
|
};
|
|
843
1343
|
if (this.options.key && this.options.cert) {
|
|
@@ -845,23 +1345,23 @@
|
|
|
845
1345
|
serveOptions.key = this.options.key;
|
|
846
1346
|
}
|
|
847
1347
|
this.nativeServer = Deno.serve(serveOptions);
|
|
848
|
-
|
|
1348
|
+
emitListeningWithCallback(this, callback);
|
|
849
1349
|
}
|
|
850
1350
|
return this;
|
|
851
1351
|
}
|
|
852
1352
|
close(callback) {
|
|
853
1353
|
if (!this.nativeServer) {
|
|
854
|
-
if (callback)
|
|
1354
|
+
if (callback) queueCallback(() => callback());
|
|
855
1355
|
return this;
|
|
856
1356
|
}
|
|
857
1357
|
if (isNode) {
|
|
858
1358
|
this.nativeServer.close(callback);
|
|
859
1359
|
} else if (isBun) {
|
|
860
1360
|
this.nativeServer.stop();
|
|
861
|
-
|
|
1361
|
+
closeAndEmit(this, callback);
|
|
862
1362
|
} else if (isDeno) {
|
|
863
1363
|
this.nativeServer.shutdown();
|
|
864
|
-
|
|
1364
|
+
closeAndEmit(this, callback);
|
|
865
1365
|
}
|
|
866
1366
|
return this;
|
|
867
1367
|
}
|
|
@@ -871,14 +1371,16 @@
|
|
|
871
1371
|
const addr = this.nativeServer.address();
|
|
872
1372
|
if (!addr) return null;
|
|
873
1373
|
if (typeof addr === "string") {
|
|
874
|
-
return
|
|
1374
|
+
return createAddress(0, addr, "unix");
|
|
875
1375
|
}
|
|
876
1376
|
return addr;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
1377
|
+
}
|
|
1378
|
+
if (isBun) {
|
|
1379
|
+
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
1380
|
+
}
|
|
1381
|
+
if (isDeno) {
|
|
880
1382
|
const addr = this.nativeServer.addr;
|
|
881
|
-
return
|
|
1383
|
+
return createAddress(addr.port, addr.hostname);
|
|
882
1384
|
}
|
|
883
1385
|
return null;
|
|
884
1386
|
}
|
|
@@ -886,78 +1388,18 @@
|
|
|
886
1388
|
return this._listening;
|
|
887
1389
|
}
|
|
888
1390
|
};
|
|
889
|
-
|
|
890
|
-
constructor(_url, _options = {}) {
|
|
891
|
-
super();
|
|
892
|
-
}
|
|
893
|
-
write(_chunk) {
|
|
894
|
-
return true;
|
|
895
|
-
}
|
|
896
|
-
end(callback) {
|
|
897
|
-
queueCallback2(callback);
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
var Agent2 = class {
|
|
901
|
-
constructor(options) {
|
|
902
|
-
this.options = options;
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
function createServer2(options, requestListener) {
|
|
1391
|
+
function createServer2(options = {}, requestListener) {
|
|
906
1392
|
return new Server2(options, requestListener);
|
|
907
1393
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const req = new ClientRequest2(urlString, options);
|
|
911
|
-
if (isNode) {
|
|
912
|
-
const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
|
|
913
|
-
if (!https2) https2 = __require("https");
|
|
914
|
-
const nodeReq = https2.request(urlString, {
|
|
915
|
-
method: options?.method || "GET",
|
|
916
|
-
headers: options?.headers,
|
|
917
|
-
timeout: options?.timeout,
|
|
918
|
-
signal: options?.signal
|
|
919
|
-
}, (res) => {
|
|
920
|
-
const incomingMessage = new IncomingMessage2(res);
|
|
921
|
-
if (callback) callback(incomingMessage);
|
|
922
|
-
req.emit("response", incomingMessage);
|
|
923
|
-
});
|
|
924
|
-
nodeReq.on("error", (error) => req.emit("error", error));
|
|
925
|
-
nodeReq.end();
|
|
926
|
-
} else {
|
|
927
|
-
const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
|
|
928
|
-
queueMicrotask(async () => {
|
|
929
|
-
try {
|
|
930
|
-
const response = await fetch(urlString, {
|
|
931
|
-
method: options?.method || "GET",
|
|
932
|
-
headers: options?.headers,
|
|
933
|
-
signal: options?.signal
|
|
934
|
-
});
|
|
935
|
-
const fetchRequest = new Request(urlString);
|
|
936
|
-
const incomingMessage = new IncomingMessage2(fetchRequest);
|
|
937
|
-
incomingMessage.statusCode = response.status;
|
|
938
|
-
incomingMessage.statusMessage = response.statusText;
|
|
939
|
-
if (callback) callback(incomingMessage);
|
|
940
|
-
req.emit("response", incomingMessage);
|
|
941
|
-
} catch (error) {
|
|
942
|
-
req.emit("error", error);
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
return req;
|
|
947
|
-
}
|
|
948
|
-
function get2(url, options, callback) {
|
|
949
|
-
return request2(url, { ...options, method: "GET" }, callback);
|
|
950
|
-
}
|
|
951
|
-
function getRuntime2() {
|
|
952
|
-
return runtime;
|
|
953
|
-
}
|
|
1394
|
+
|
|
1395
|
+
// src/server/https/index.ts
|
|
954
1396
|
var https_default = {
|
|
955
1397
|
createServer: createServer2,
|
|
956
1398
|
request: request2,
|
|
957
1399
|
get: get2,
|
|
958
1400
|
Server: Server2,
|
|
959
|
-
Agent
|
|
960
|
-
ClientRequest
|
|
1401
|
+
Agent,
|
|
1402
|
+
ClientRequest,
|
|
961
1403
|
getRuntime: getRuntime2
|
|
962
1404
|
};
|
|
963
1405
|
})();
|