@vitejs/devtools 0.0.0-alpha.2 → 0.0.0-alpha.21
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/cli-commands-CkG1gOFc.js +96 -0
- package/dist/cli-commands.d.ts +18 -0
- package/dist/cli-commands.js +4 -0
- package/dist/cli.js +4 -71
- package/dist/client/inject.js +97 -14
- package/dist/client/standalone/assets/index-Dpn5Nv-R.js +7 -0
- package/dist/client/standalone/assets/index-bVBlMYV3.css +1 -0
- package/dist/client/standalone/index.html +3 -3
- package/dist/client/webcomponents.d.ts +26 -30
- package/dist/client/webcomponents.js +797 -303
- package/dist/{dirs-B7dOX6eI.js → dirs-C0s1Ghvy.js} +1 -1
- package/dist/dirs.js +1 -1
- package/dist/{core-uTAXYiA1.js → docks-BuqYBItp.js} +1348 -1175
- package/dist/index-CWvzFILY.d.ts +493 -0
- package/dist/index.d.ts +38 -5
- package/dist/index.js +1 -55
- package/dist/plugins-Chcj6ENu.js +2756 -0
- package/package.json +27 -16
- package/dist/client/standalone/assets/index-7RajWZLR.css +0 -1
- package/dist/client/standalone/assets/index-BZuCeFpb.js +0 -7
- package/dist/server-B_q0HJ88.js +0 -1262
package/dist/server-B_q0HJ88.js
DELETED
|
@@ -1,1262 +0,0 @@
|
|
|
1
|
-
import { dirClientStandalone } from "./dirs-B7dOX6eI.js";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import Debug from "debug";
|
|
4
|
-
import sirv from "sirv";
|
|
5
|
-
import { defineRpcFunction, getRpcHandler } from "@vitejs/devtools-kit";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { createRpcServer } from "@vitejs/devtools-rpc";
|
|
8
|
-
import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/server";
|
|
9
|
-
import { createServer } from "node:net";
|
|
10
|
-
import { networkInterfaces } from "node:os";
|
|
11
|
-
import "node:fs/promises";
|
|
12
|
-
|
|
13
|
-
//#region rolldown:runtime
|
|
14
|
-
var __create = Object.create;
|
|
15
|
-
var __defProp = Object.defineProperty;
|
|
16
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
17
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
18
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
19
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
20
|
-
var __commonJS = (cb, mod) => function() {
|
|
21
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
22
|
-
};
|
|
23
|
-
var __copyProps = (to, from, except, desc) => {
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i$1 = 0, n$1 = keys.length, key; i$1 < n$1; i$1++) {
|
|
25
|
-
key = keys[i$1];
|
|
26
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
27
|
-
get: ((k) => from[k]).bind(null, key),
|
|
28
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
34
|
-
value: mod,
|
|
35
|
-
enumerable: true
|
|
36
|
-
}) : target, mod));
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/node/host-docks.ts
|
|
40
|
-
var DevToolsDockHost = class {
|
|
41
|
-
views = /* @__PURE__ */ new Map();
|
|
42
|
-
constructor() {}
|
|
43
|
-
values() {
|
|
44
|
-
return Array.from(this.views.values());
|
|
45
|
-
}
|
|
46
|
-
register(view) {
|
|
47
|
-
this.views.set(view.id, view);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/node/host-functions.ts
|
|
53
|
-
var RpcFunctionsHost = class {
|
|
54
|
-
definitions = /* @__PURE__ */ new Map();
|
|
55
|
-
functions;
|
|
56
|
-
context = void 0;
|
|
57
|
-
constructor() {
|
|
58
|
-
const definitions = this.definitions;
|
|
59
|
-
const self = this;
|
|
60
|
-
this.functions = new Proxy({}, {
|
|
61
|
-
get(_, prop) {
|
|
62
|
-
const definition = definitions.get(prop);
|
|
63
|
-
if (!definition) return void 0;
|
|
64
|
-
return getRpcHandler(definition, self.context);
|
|
65
|
-
},
|
|
66
|
-
has(_, prop) {
|
|
67
|
-
return definitions.has(prop);
|
|
68
|
-
},
|
|
69
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
70
|
-
return {
|
|
71
|
-
value: definitions.get(prop)?.handler,
|
|
72
|
-
configurable: true,
|
|
73
|
-
enumerable: true
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
ownKeys() {
|
|
77
|
-
return Array.from(definitions.keys());
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
register(fn) {
|
|
82
|
-
this.definitions.set(fn.name, fn);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/node/rpc/list-dock-entries.ts
|
|
88
|
-
const listDockEntries = defineRpcFunction({
|
|
89
|
-
name: "vite:core:list-dock-entries",
|
|
90
|
-
type: "query",
|
|
91
|
-
setup: (context) => {
|
|
92
|
-
return { handler: () => Array.from(context.docks.values()) };
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/node/rpc/list-rpc-functions.ts
|
|
98
|
-
const listRpcFunctions = defineRpcFunction({
|
|
99
|
-
name: "vite:core:list-rpc-functions",
|
|
100
|
-
type: "action",
|
|
101
|
-
setup: (context) => {
|
|
102
|
-
return { async handler() {
|
|
103
|
-
return Object.fromEntries(Array.from(context.rpc.definitions.entries()).map(([name, fn]) => [name, { type: fn.type }]));
|
|
104
|
-
} };
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/node/rpc/open-in-editor.ts
|
|
110
|
-
const openInEditor = defineRpcFunction({
|
|
111
|
-
name: "vite:core:open-in-editor",
|
|
112
|
-
type: "action",
|
|
113
|
-
setup: () => {
|
|
114
|
-
return { handler: async (path) => {
|
|
115
|
-
await import("launch-editor").then((r$2) => r$2.default(path));
|
|
116
|
-
} };
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/node/rpc/open-in-finder.ts
|
|
122
|
-
const openInFinder = defineRpcFunction({
|
|
123
|
-
name: "vite:core:open-in-finder",
|
|
124
|
-
type: "action",
|
|
125
|
-
setup: () => {
|
|
126
|
-
return { handler: async (path) => {
|
|
127
|
-
await import("open").then((r$2) => r$2.default(path));
|
|
128
|
-
} };
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/node/rpc/index.ts
|
|
134
|
-
const builtinRpcFunctions = [
|
|
135
|
-
listRpcFunctions,
|
|
136
|
-
listDockEntries,
|
|
137
|
-
openInEditor,
|
|
138
|
-
openInFinder
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/node/context.ts
|
|
143
|
-
const debug = Debug("vite:devtools:context");
|
|
144
|
-
async function createDevToolsContext(viteConfig, viteServer) {
|
|
145
|
-
const cwd = viteConfig.root;
|
|
146
|
-
const rpcHost = new RpcFunctionsHost();
|
|
147
|
-
const docksHost = new DevToolsDockHost();
|
|
148
|
-
const context = {
|
|
149
|
-
cwd,
|
|
150
|
-
viteConfig,
|
|
151
|
-
viteServer,
|
|
152
|
-
mode: viteConfig.command === "serve" ? "dev" : "build",
|
|
153
|
-
rpc: rpcHost,
|
|
154
|
-
docks: docksHost,
|
|
155
|
-
hostStatic,
|
|
156
|
-
staticDirs: []
|
|
157
|
-
};
|
|
158
|
-
rpcHost.context = context;
|
|
159
|
-
function hostStatic(baseUrl, distDir) {
|
|
160
|
-
if (!existsSync(distDir)) throw new Error(`[Vite DevTools] distDir ${distDir} does not exist`);
|
|
161
|
-
if (viteConfig.command === "serve") {
|
|
162
|
-
if (!viteServer) throw new Error("[Vite DevTools] viteServer is required in dev mode");
|
|
163
|
-
viteServer.middlewares.use(baseUrl, sirv(distDir, {
|
|
164
|
-
dev: true,
|
|
165
|
-
single: true
|
|
166
|
-
}));
|
|
167
|
-
} else context.staticDirs.push({
|
|
168
|
-
baseUrl,
|
|
169
|
-
distDir
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
for (const fn of builtinRpcFunctions) rpcHost.register(fn);
|
|
173
|
-
const plugins = viteConfig.plugins.filter((plugin) => "devtools" in plugin);
|
|
174
|
-
for (const plugin of plugins) {
|
|
175
|
-
if (!plugin.devtools?.setup) continue;
|
|
176
|
-
try {
|
|
177
|
-
debug(`Setting up plugin ${plugin.name}`);
|
|
178
|
-
await plugin.devtools?.setup?.(context);
|
|
179
|
-
} catch (error) {
|
|
180
|
-
console.error(`[Vite DevTools] Error setting up plugin ${plugin.name}:`, error);
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return context;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region ../../node_modules/.pnpm/ufo@1.6.1/node_modules/ufo/dist/index.mjs
|
|
189
|
-
const r$1 = String.fromCharCode;
|
|
190
|
-
const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
|
|
191
|
-
const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
|
|
192
|
-
const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
|
|
193
|
-
const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
|
|
194
|
-
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
195
|
-
function hasProtocol(inputString, opts = {}) {
|
|
196
|
-
if (typeof opts === "boolean") opts = { acceptRelative: opts };
|
|
197
|
-
if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
|
|
198
|
-
return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
|
|
199
|
-
}
|
|
200
|
-
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
201
|
-
if (!respectQueryAndFragment) return input.endsWith("/");
|
|
202
|
-
return TRAILING_SLASH_RE.test(input);
|
|
203
|
-
}
|
|
204
|
-
function withoutTrailingSlash(input = "", respectQueryAndFragment) {
|
|
205
|
-
if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
|
206
|
-
if (!hasTrailingSlash(input, true)) return input || "/";
|
|
207
|
-
let path = input;
|
|
208
|
-
let fragment = "";
|
|
209
|
-
const fragmentIndex = input.indexOf("#");
|
|
210
|
-
if (fragmentIndex !== -1) {
|
|
211
|
-
path = input.slice(0, fragmentIndex);
|
|
212
|
-
fragment = input.slice(fragmentIndex);
|
|
213
|
-
}
|
|
214
|
-
const [s0, ...s$1] = path.split("?");
|
|
215
|
-
return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s$1.length > 0 ? `?${s$1.join("?")}` : "") + fragment;
|
|
216
|
-
}
|
|
217
|
-
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
218
|
-
if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
|
|
219
|
-
if (hasTrailingSlash(input, true)) return input || "/";
|
|
220
|
-
let path = input;
|
|
221
|
-
let fragment = "";
|
|
222
|
-
const fragmentIndex = input.indexOf("#");
|
|
223
|
-
if (fragmentIndex !== -1) {
|
|
224
|
-
path = input.slice(0, fragmentIndex);
|
|
225
|
-
fragment = input.slice(fragmentIndex);
|
|
226
|
-
if (!path) return fragment;
|
|
227
|
-
}
|
|
228
|
-
const [s0, ...s$1] = path.split("?");
|
|
229
|
-
return s0 + "/" + (s$1.length > 0 ? `?${s$1.join("?")}` : "") + fragment;
|
|
230
|
-
}
|
|
231
|
-
function isNonEmptyURL(url) {
|
|
232
|
-
return url && url !== "/";
|
|
233
|
-
}
|
|
234
|
-
function joinURL(base, ...input) {
|
|
235
|
-
let url = base || "";
|
|
236
|
-
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
|
|
237
|
-
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
238
|
-
url = withTrailingSlash(url) + _segment;
|
|
239
|
-
} else url = segment;
|
|
240
|
-
return url;
|
|
241
|
-
}
|
|
242
|
-
const protocolRelative = Symbol.for("ufo:protocolRelative");
|
|
243
|
-
function parseURL(input = "", defaultProto) {
|
|
244
|
-
const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
|
|
245
|
-
if (_specialProtoMatch) {
|
|
246
|
-
const [, _proto, _pathname = ""] = _specialProtoMatch;
|
|
247
|
-
return {
|
|
248
|
-
protocol: _proto.toLowerCase(),
|
|
249
|
-
pathname: _pathname,
|
|
250
|
-
href: _proto + _pathname,
|
|
251
|
-
auth: "",
|
|
252
|
-
host: "",
|
|
253
|
-
search: "",
|
|
254
|
-
hash: ""
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
|
258
|
-
const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
|
|
259
|
-
let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
|
|
260
|
-
if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
|
|
261
|
-
const { pathname, search, hash } = parsePath(path);
|
|
262
|
-
return {
|
|
263
|
-
protocol: protocol.toLowerCase(),
|
|
264
|
-
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
|
265
|
-
host,
|
|
266
|
-
pathname,
|
|
267
|
-
search,
|
|
268
|
-
hash,
|
|
269
|
-
[protocolRelative]: !protocol
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function parsePath(input = "") {
|
|
273
|
-
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
|
274
|
-
return {
|
|
275
|
-
pathname,
|
|
276
|
-
search,
|
|
277
|
-
hash
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
283
|
-
function isPlainObject(value) {
|
|
284
|
-
if (value === null || typeof value !== "object") return false;
|
|
285
|
-
const prototype = Object.getPrototypeOf(value);
|
|
286
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
287
|
-
if (Symbol.iterator in value) return false;
|
|
288
|
-
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
292
|
-
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
293
|
-
const object = Object.assign({}, defaults);
|
|
294
|
-
for (const key in baseObject) {
|
|
295
|
-
if (key === "__proto__" || key === "constructor") continue;
|
|
296
|
-
const value = baseObject[key];
|
|
297
|
-
if (value === null || value === void 0) continue;
|
|
298
|
-
if (merger && merger(object, key, value, namespace)) continue;
|
|
299
|
-
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
300
|
-
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
301
|
-
else object[key] = value;
|
|
302
|
-
}
|
|
303
|
-
return object;
|
|
304
|
-
}
|
|
305
|
-
function createDefu(merger) {
|
|
306
|
-
return (...arguments_) => arguments_.reduce((p$1, c$1) => _defu(p$1, c$1, "", merger), {});
|
|
307
|
-
}
|
|
308
|
-
const defu = createDefu();
|
|
309
|
-
const defuFn = createDefu((object, key, currentValue) => {
|
|
310
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
311
|
-
object[key] = currentValue(object[key]);
|
|
312
|
-
return true;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
const defuArrayFn = createDefu((object, key, currentValue) => {
|
|
316
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
317
|
-
object[key] = currentValue(object[key]);
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region ../../node_modules/.pnpm/h3@1.15.4/node_modules/h3/dist/index.mjs
|
|
324
|
-
function hasProp(obj, prop) {
|
|
325
|
-
try {
|
|
326
|
-
return prop in obj;
|
|
327
|
-
} catch {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
var H3Error = class extends Error {
|
|
332
|
-
static __h3_error__ = true;
|
|
333
|
-
statusCode = 500;
|
|
334
|
-
fatal = false;
|
|
335
|
-
unhandled = false;
|
|
336
|
-
statusMessage;
|
|
337
|
-
data;
|
|
338
|
-
cause;
|
|
339
|
-
constructor(message, opts = {}) {
|
|
340
|
-
super(message, opts);
|
|
341
|
-
if (opts.cause && !this.cause) this.cause = opts.cause;
|
|
342
|
-
}
|
|
343
|
-
toJSON() {
|
|
344
|
-
const obj = {
|
|
345
|
-
message: this.message,
|
|
346
|
-
statusCode: sanitizeStatusCode(this.statusCode, 500)
|
|
347
|
-
};
|
|
348
|
-
if (this.statusMessage) obj.statusMessage = sanitizeStatusMessage(this.statusMessage);
|
|
349
|
-
if (this.data !== void 0) obj.data = this.data;
|
|
350
|
-
return obj;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
function createError(input) {
|
|
354
|
-
if (typeof input === "string") return new H3Error(input);
|
|
355
|
-
if (isError(input)) return input;
|
|
356
|
-
const err = new H3Error(input.message ?? input.statusMessage ?? "", { cause: input.cause || input });
|
|
357
|
-
if (hasProp(input, "stack")) try {
|
|
358
|
-
Object.defineProperty(err, "stack", { get() {
|
|
359
|
-
return input.stack;
|
|
360
|
-
} });
|
|
361
|
-
} catch {
|
|
362
|
-
try {
|
|
363
|
-
err.stack = input.stack;
|
|
364
|
-
} catch {}
|
|
365
|
-
}
|
|
366
|
-
if (input.data) err.data = input.data;
|
|
367
|
-
if (input.statusCode) err.statusCode = sanitizeStatusCode(input.statusCode, err.statusCode);
|
|
368
|
-
else if (input.status) err.statusCode = sanitizeStatusCode(input.status, err.statusCode);
|
|
369
|
-
if (input.statusMessage) err.statusMessage = input.statusMessage;
|
|
370
|
-
else if (input.statusText) err.statusMessage = input.statusText;
|
|
371
|
-
if (err.statusMessage) {
|
|
372
|
-
const originalMessage = err.statusMessage;
|
|
373
|
-
if (sanitizeStatusMessage(err.statusMessage) !== originalMessage) console.warn("[h3] Please prefer using `message` for longer error messages instead of `statusMessage`. In the future, `statusMessage` will be sanitized by default.");
|
|
374
|
-
}
|
|
375
|
-
if (input.fatal !== void 0) err.fatal = input.fatal;
|
|
376
|
-
if (input.unhandled !== void 0) err.unhandled = input.unhandled;
|
|
377
|
-
return err;
|
|
378
|
-
}
|
|
379
|
-
function sendError(event, error, debug$1) {
|
|
380
|
-
if (event.handled) return;
|
|
381
|
-
const h3Error = isError(error) ? error : createError(error);
|
|
382
|
-
const responseBody = {
|
|
383
|
-
statusCode: h3Error.statusCode,
|
|
384
|
-
statusMessage: h3Error.statusMessage,
|
|
385
|
-
stack: [],
|
|
386
|
-
data: h3Error.data
|
|
387
|
-
};
|
|
388
|
-
if (debug$1) responseBody.stack = (h3Error.stack || "").split("\n").map((l$1) => l$1.trim());
|
|
389
|
-
if (event.handled) return;
|
|
390
|
-
const _code = Number.parseInt(h3Error.statusCode);
|
|
391
|
-
setResponseStatus(event, _code, h3Error.statusMessage);
|
|
392
|
-
event.node.res.setHeader("content-type", MIMES.json);
|
|
393
|
-
event.node.res.end(JSON.stringify(responseBody, void 0, 2));
|
|
394
|
-
}
|
|
395
|
-
function isError(input) {
|
|
396
|
-
return input?.constructor?.__h3_error__ === true;
|
|
397
|
-
}
|
|
398
|
-
const RawBodySymbol = Symbol.for("h3RawBody");
|
|
399
|
-
const ParsedBodySymbol = Symbol.for("h3ParsedBody");
|
|
400
|
-
const MIMES = {
|
|
401
|
-
html: "text/html",
|
|
402
|
-
json: "application/json"
|
|
403
|
-
};
|
|
404
|
-
const DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
|
|
405
|
-
function sanitizeStatusMessage(statusMessage = "") {
|
|
406
|
-
return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
|
|
407
|
-
}
|
|
408
|
-
function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
|
|
409
|
-
if (!statusCode) return defaultStatusCode;
|
|
410
|
-
if (typeof statusCode === "string") statusCode = Number.parseInt(statusCode, 10);
|
|
411
|
-
if (statusCode < 100 || statusCode > 999) return defaultStatusCode;
|
|
412
|
-
return statusCode;
|
|
413
|
-
}
|
|
414
|
-
function splitCookiesString(cookiesString) {
|
|
415
|
-
if (Array.isArray(cookiesString)) return cookiesString.flatMap((c$1) => splitCookiesString(c$1));
|
|
416
|
-
if (typeof cookiesString !== "string") return [];
|
|
417
|
-
const cookiesStrings = [];
|
|
418
|
-
let pos = 0;
|
|
419
|
-
let start;
|
|
420
|
-
let ch;
|
|
421
|
-
let lastComma;
|
|
422
|
-
let nextStart;
|
|
423
|
-
let cookiesSeparatorFound;
|
|
424
|
-
const skipWhitespace = () => {
|
|
425
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
|
|
426
|
-
return pos < cookiesString.length;
|
|
427
|
-
};
|
|
428
|
-
const notSpecialChar = () => {
|
|
429
|
-
ch = cookiesString.charAt(pos);
|
|
430
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
431
|
-
};
|
|
432
|
-
while (pos < cookiesString.length) {
|
|
433
|
-
start = pos;
|
|
434
|
-
cookiesSeparatorFound = false;
|
|
435
|
-
while (skipWhitespace()) {
|
|
436
|
-
ch = cookiesString.charAt(pos);
|
|
437
|
-
if (ch === ",") {
|
|
438
|
-
lastComma = pos;
|
|
439
|
-
pos += 1;
|
|
440
|
-
skipWhitespace();
|
|
441
|
-
nextStart = pos;
|
|
442
|
-
while (pos < cookiesString.length && notSpecialChar()) pos += 1;
|
|
443
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
444
|
-
cookiesSeparatorFound = true;
|
|
445
|
-
pos = nextStart;
|
|
446
|
-
cookiesStrings.push(cookiesString.slice(start, lastComma));
|
|
447
|
-
start = pos;
|
|
448
|
-
} else pos = lastComma + 1;
|
|
449
|
-
} else pos += 1;
|
|
450
|
-
}
|
|
451
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
|
|
452
|
-
}
|
|
453
|
-
return cookiesStrings;
|
|
454
|
-
}
|
|
455
|
-
const defer = typeof setImmediate === "undefined" ? (fn) => fn() : setImmediate;
|
|
456
|
-
function send(event, data, type) {
|
|
457
|
-
if (type) defaultContentType(event, type);
|
|
458
|
-
return new Promise((resolve) => {
|
|
459
|
-
defer(() => {
|
|
460
|
-
if (!event.handled) event.node.res.end(data);
|
|
461
|
-
resolve();
|
|
462
|
-
});
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
function sendNoContent(event, code) {
|
|
466
|
-
if (event.handled) return;
|
|
467
|
-
if (!code && event.node.res.statusCode !== 200) code = event.node.res.statusCode;
|
|
468
|
-
const _code = sanitizeStatusCode(code, 204);
|
|
469
|
-
if (_code === 204) event.node.res.removeHeader("content-length");
|
|
470
|
-
event.node.res.writeHead(_code);
|
|
471
|
-
event.node.res.end();
|
|
472
|
-
}
|
|
473
|
-
function setResponseStatus(event, code, text) {
|
|
474
|
-
if (code) event.node.res.statusCode = sanitizeStatusCode(code, event.node.res.statusCode);
|
|
475
|
-
if (text) event.node.res.statusMessage = sanitizeStatusMessage(text);
|
|
476
|
-
}
|
|
477
|
-
function defaultContentType(event, type) {
|
|
478
|
-
if (type && event.node.res.statusCode !== 304 && !event.node.res.getHeader("content-type")) event.node.res.setHeader("content-type", type);
|
|
479
|
-
}
|
|
480
|
-
function sendRedirect(event, location, code = 302) {
|
|
481
|
-
event.node.res.statusCode = sanitizeStatusCode(code, event.node.res.statusCode);
|
|
482
|
-
event.node.res.setHeader("location", location);
|
|
483
|
-
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${location.replace(/"/g, "%22")}"></head></html>`;
|
|
484
|
-
return send(event, html, MIMES.html);
|
|
485
|
-
}
|
|
486
|
-
function isStream(data) {
|
|
487
|
-
if (!data || typeof data !== "object") return false;
|
|
488
|
-
if (typeof data.pipe === "function") {
|
|
489
|
-
if (typeof data._read === "function") return true;
|
|
490
|
-
if (typeof data.abort === "function") return true;
|
|
491
|
-
}
|
|
492
|
-
if (typeof data.pipeTo === "function") return true;
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
function isWebResponse(data) {
|
|
496
|
-
return typeof Response !== "undefined" && data instanceof Response;
|
|
497
|
-
}
|
|
498
|
-
function sendStream(event, stream) {
|
|
499
|
-
if (!stream || typeof stream !== "object") throw new Error("[h3] Invalid stream provided.");
|
|
500
|
-
event.node.res._data = stream;
|
|
501
|
-
if (!event.node.res.socket) {
|
|
502
|
-
event._handled = true;
|
|
503
|
-
return Promise.resolve();
|
|
504
|
-
}
|
|
505
|
-
if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") return stream.pipeTo(new WritableStream({ write(chunk) {
|
|
506
|
-
event.node.res.write(chunk);
|
|
507
|
-
} })).then(() => {
|
|
508
|
-
event.node.res.end();
|
|
509
|
-
});
|
|
510
|
-
if (hasProp(stream, "pipe") && typeof stream.pipe === "function") return new Promise((resolve, reject) => {
|
|
511
|
-
stream.pipe(event.node.res);
|
|
512
|
-
if (stream.on) {
|
|
513
|
-
stream.on("end", () => {
|
|
514
|
-
event.node.res.end();
|
|
515
|
-
resolve();
|
|
516
|
-
});
|
|
517
|
-
stream.on("error", (error) => {
|
|
518
|
-
reject(error);
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
event.node.res.on("close", () => {
|
|
522
|
-
if (stream.abort) stream.abort();
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
throw new Error("[h3] Invalid or incompatible stream provided.");
|
|
526
|
-
}
|
|
527
|
-
function sendWebResponse(event, response) {
|
|
528
|
-
for (const [key, value] of response.headers) if (key === "set-cookie") event.node.res.appendHeader(key, splitCookiesString(value));
|
|
529
|
-
else event.node.res.setHeader(key, value);
|
|
530
|
-
if (response.status) event.node.res.statusCode = sanitizeStatusCode(response.status, event.node.res.statusCode);
|
|
531
|
-
if (response.statusText) event.node.res.statusMessage = sanitizeStatusMessage(response.statusText);
|
|
532
|
-
if (response.redirected) event.node.res.setHeader("location", response.url);
|
|
533
|
-
if (!response.body) {
|
|
534
|
-
event.node.res.end();
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
return sendStream(event, response.body);
|
|
538
|
-
}
|
|
539
|
-
const getSessionPromise = Symbol("getSession");
|
|
540
|
-
var H3Event = class {
|
|
541
|
-
"__is_event__" = true;
|
|
542
|
-
node;
|
|
543
|
-
web;
|
|
544
|
-
context = {};
|
|
545
|
-
_method;
|
|
546
|
-
_path;
|
|
547
|
-
_headers;
|
|
548
|
-
_requestBody;
|
|
549
|
-
_handled = false;
|
|
550
|
-
_onBeforeResponseCalled;
|
|
551
|
-
_onAfterResponseCalled;
|
|
552
|
-
constructor(req, res) {
|
|
553
|
-
this.node = {
|
|
554
|
-
req,
|
|
555
|
-
res
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
get method() {
|
|
559
|
-
if (!this._method) this._method = (this.node.req.method || "GET").toUpperCase();
|
|
560
|
-
return this._method;
|
|
561
|
-
}
|
|
562
|
-
get path() {
|
|
563
|
-
return this._path || this.node.req.url || "/";
|
|
564
|
-
}
|
|
565
|
-
get headers() {
|
|
566
|
-
if (!this._headers) this._headers = _normalizeNodeHeaders(this.node.req.headers);
|
|
567
|
-
return this._headers;
|
|
568
|
-
}
|
|
569
|
-
get handled() {
|
|
570
|
-
return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
|
|
571
|
-
}
|
|
572
|
-
respondWith(response) {
|
|
573
|
-
return Promise.resolve(response).then((_response) => sendWebResponse(this, _response));
|
|
574
|
-
}
|
|
575
|
-
toString() {
|
|
576
|
-
return `[${this.method}] ${this.path}`;
|
|
577
|
-
}
|
|
578
|
-
toJSON() {
|
|
579
|
-
return this.toString();
|
|
580
|
-
}
|
|
581
|
-
/** @deprecated Please use `event.node.req` instead. */
|
|
582
|
-
get req() {
|
|
583
|
-
return this.node.req;
|
|
584
|
-
}
|
|
585
|
-
/** @deprecated Please use `event.node.res` instead. */
|
|
586
|
-
get res() {
|
|
587
|
-
return this.node.res;
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
function createEvent(req, res) {
|
|
591
|
-
return new H3Event(req, res);
|
|
592
|
-
}
|
|
593
|
-
function _normalizeNodeHeaders(nodeHeaders) {
|
|
594
|
-
const headers = new Headers();
|
|
595
|
-
for (const [name, value] of Object.entries(nodeHeaders)) if (Array.isArray(value)) for (const item of value) headers.append(name, item);
|
|
596
|
-
else if (value) headers.set(name, value);
|
|
597
|
-
return headers;
|
|
598
|
-
}
|
|
599
|
-
function defineEventHandler(handler) {
|
|
600
|
-
if (typeof handler === "function") {
|
|
601
|
-
handler.__is_handler__ = true;
|
|
602
|
-
return handler;
|
|
603
|
-
}
|
|
604
|
-
const _hooks = {
|
|
605
|
-
onRequest: _normalizeArray(handler.onRequest),
|
|
606
|
-
onBeforeResponse: _normalizeArray(handler.onBeforeResponse)
|
|
607
|
-
};
|
|
608
|
-
const _handler = (event) => {
|
|
609
|
-
return _callHandler(event, handler.handler, _hooks);
|
|
610
|
-
};
|
|
611
|
-
_handler.__is_handler__ = true;
|
|
612
|
-
_handler.__resolve__ = handler.handler.__resolve__;
|
|
613
|
-
_handler.__websocket__ = handler.websocket;
|
|
614
|
-
return _handler;
|
|
615
|
-
}
|
|
616
|
-
function _normalizeArray(input) {
|
|
617
|
-
return input ? Array.isArray(input) ? input : [input] : void 0;
|
|
618
|
-
}
|
|
619
|
-
async function _callHandler(event, handler, hooks) {
|
|
620
|
-
if (hooks.onRequest) for (const hook of hooks.onRequest) {
|
|
621
|
-
await hook(event);
|
|
622
|
-
if (event.handled) return;
|
|
623
|
-
}
|
|
624
|
-
const response = { body: await handler(event) };
|
|
625
|
-
if (hooks.onBeforeResponse) for (const hook of hooks.onBeforeResponse) await hook(event, response);
|
|
626
|
-
return response.body;
|
|
627
|
-
}
|
|
628
|
-
const eventHandler = defineEventHandler;
|
|
629
|
-
function isEventHandler(input) {
|
|
630
|
-
return hasProp(input, "__is_handler__");
|
|
631
|
-
}
|
|
632
|
-
function toEventHandler(input, _, _route) {
|
|
633
|
-
if (!isEventHandler(input)) console.warn("[h3] Implicit event handler conversion is deprecated. Use `eventHandler()` or `fromNodeMiddleware()` to define event handlers.", _route && _route !== "/" ? `
|
|
634
|
-
Route: ${_route}` : "", `
|
|
635
|
-
Handler: ${input}`);
|
|
636
|
-
return input;
|
|
637
|
-
}
|
|
638
|
-
function defineLazyEventHandler(factory) {
|
|
639
|
-
let _promise;
|
|
640
|
-
let _resolved;
|
|
641
|
-
const resolveHandler = () => {
|
|
642
|
-
if (_resolved) return Promise.resolve(_resolved);
|
|
643
|
-
if (!_promise) _promise = Promise.resolve(factory()).then((r$2) => {
|
|
644
|
-
const handler2 = r$2.default || r$2;
|
|
645
|
-
if (typeof handler2 !== "function") throw new TypeError("Invalid lazy handler result. It should be a function:", handler2);
|
|
646
|
-
_resolved = { handler: toEventHandler(r$2.default || r$2) };
|
|
647
|
-
return _resolved;
|
|
648
|
-
});
|
|
649
|
-
return _promise;
|
|
650
|
-
};
|
|
651
|
-
const handler = eventHandler((event) => {
|
|
652
|
-
if (_resolved) return _resolved.handler(event);
|
|
653
|
-
return resolveHandler().then((r$2) => r$2.handler(event));
|
|
654
|
-
});
|
|
655
|
-
handler.__resolve__ = resolveHandler;
|
|
656
|
-
return handler;
|
|
657
|
-
}
|
|
658
|
-
const lazyEventHandler = defineLazyEventHandler;
|
|
659
|
-
const H3Headers = globalThis.Headers;
|
|
660
|
-
const H3Response = globalThis.Response;
|
|
661
|
-
function createApp(options = {}) {
|
|
662
|
-
const stack = [];
|
|
663
|
-
const handler = createAppEventHandler(stack, options);
|
|
664
|
-
const resolve = createResolver(stack);
|
|
665
|
-
handler.__resolve__ = resolve;
|
|
666
|
-
const getWebsocket = cachedFn(() => websocketOptions(resolve, options));
|
|
667
|
-
const app = {
|
|
668
|
-
use: (arg1, arg2, arg3) => use(app, arg1, arg2, arg3),
|
|
669
|
-
resolve,
|
|
670
|
-
handler,
|
|
671
|
-
stack,
|
|
672
|
-
options,
|
|
673
|
-
get websocket() {
|
|
674
|
-
return getWebsocket();
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
return app;
|
|
678
|
-
}
|
|
679
|
-
function use(app, arg1, arg2, arg3) {
|
|
680
|
-
if (Array.isArray(arg1)) for (const i$1 of arg1) use(app, i$1, arg2, arg3);
|
|
681
|
-
else if (Array.isArray(arg2)) for (const i$1 of arg2) use(app, arg1, i$1, arg3);
|
|
682
|
-
else if (typeof arg1 === "string") app.stack.push(normalizeLayer({
|
|
683
|
-
...arg3,
|
|
684
|
-
route: arg1,
|
|
685
|
-
handler: arg2
|
|
686
|
-
}));
|
|
687
|
-
else if (typeof arg1 === "function") app.stack.push(normalizeLayer({
|
|
688
|
-
...arg2,
|
|
689
|
-
handler: arg1
|
|
690
|
-
}));
|
|
691
|
-
else app.stack.push(normalizeLayer({ ...arg1 }));
|
|
692
|
-
return app;
|
|
693
|
-
}
|
|
694
|
-
function createAppEventHandler(stack, options) {
|
|
695
|
-
const spacing = options.debug ? 2 : void 0;
|
|
696
|
-
return eventHandler(async (event) => {
|
|
697
|
-
event.node.req.originalUrl = event.node.req.originalUrl || event.node.req.url || "/";
|
|
698
|
-
const _reqPath = event._path || event.node.req.url || "/";
|
|
699
|
-
let _layerPath;
|
|
700
|
-
if (options.onRequest) await options.onRequest(event);
|
|
701
|
-
for (const layer of stack) {
|
|
702
|
-
if (layer.route.length > 1) {
|
|
703
|
-
if (!_reqPath.startsWith(layer.route)) continue;
|
|
704
|
-
_layerPath = _reqPath.slice(layer.route.length) || "/";
|
|
705
|
-
} else _layerPath = _reqPath;
|
|
706
|
-
if (layer.match && !layer.match(_layerPath, event)) continue;
|
|
707
|
-
event._path = _layerPath;
|
|
708
|
-
event.node.req.url = _layerPath;
|
|
709
|
-
const val = await layer.handler(event);
|
|
710
|
-
const _body = val === void 0 ? void 0 : await val;
|
|
711
|
-
if (_body !== void 0) {
|
|
712
|
-
const _response = { body: _body };
|
|
713
|
-
if (options.onBeforeResponse) {
|
|
714
|
-
event._onBeforeResponseCalled = true;
|
|
715
|
-
await options.onBeforeResponse(event, _response);
|
|
716
|
-
}
|
|
717
|
-
await handleHandlerResponse(event, _response.body, spacing);
|
|
718
|
-
if (options.onAfterResponse) {
|
|
719
|
-
event._onAfterResponseCalled = true;
|
|
720
|
-
await options.onAfterResponse(event, _response);
|
|
721
|
-
}
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
if (event.handled) {
|
|
725
|
-
if (options.onAfterResponse) {
|
|
726
|
-
event._onAfterResponseCalled = true;
|
|
727
|
-
await options.onAfterResponse(event, void 0);
|
|
728
|
-
}
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
if (!event.handled) throw createError({
|
|
733
|
-
statusCode: 404,
|
|
734
|
-
statusMessage: `Cannot find any path matching ${event.path || "/"}.`
|
|
735
|
-
});
|
|
736
|
-
if (options.onAfterResponse) {
|
|
737
|
-
event._onAfterResponseCalled = true;
|
|
738
|
-
await options.onAfterResponse(event, void 0);
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
function createResolver(stack) {
|
|
743
|
-
return async (path) => {
|
|
744
|
-
let _layerPath;
|
|
745
|
-
for (const layer of stack) {
|
|
746
|
-
if (layer.route === "/" && !layer.handler.__resolve__) continue;
|
|
747
|
-
if (!path.startsWith(layer.route)) continue;
|
|
748
|
-
_layerPath = path.slice(layer.route.length) || "/";
|
|
749
|
-
if (layer.match && !layer.match(_layerPath, void 0)) continue;
|
|
750
|
-
let res = {
|
|
751
|
-
route: layer.route,
|
|
752
|
-
handler: layer.handler
|
|
753
|
-
};
|
|
754
|
-
if (res.handler.__resolve__) {
|
|
755
|
-
const _res = await res.handler.__resolve__(_layerPath);
|
|
756
|
-
if (!_res) continue;
|
|
757
|
-
res = {
|
|
758
|
-
...res,
|
|
759
|
-
..._res,
|
|
760
|
-
route: joinURL(res.route || "/", _res.route || "/")
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
return res;
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
function normalizeLayer(input) {
|
|
768
|
-
let handler = input.handler;
|
|
769
|
-
if (handler.handler) handler = handler.handler;
|
|
770
|
-
if (input.lazy) handler = lazyEventHandler(handler);
|
|
771
|
-
else if (!isEventHandler(handler)) handler = toEventHandler(handler, void 0, input.route);
|
|
772
|
-
return {
|
|
773
|
-
route: withoutTrailingSlash(input.route),
|
|
774
|
-
match: input.match,
|
|
775
|
-
handler
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
function handleHandlerResponse(event, val, jsonSpace) {
|
|
779
|
-
if (val === null) return sendNoContent(event);
|
|
780
|
-
if (val) {
|
|
781
|
-
if (isWebResponse(val)) return sendWebResponse(event, val);
|
|
782
|
-
if (isStream(val)) return sendStream(event, val);
|
|
783
|
-
if (val.buffer) return send(event, val);
|
|
784
|
-
if (val.arrayBuffer && typeof val.arrayBuffer === "function") return val.arrayBuffer().then((arrayBuffer) => {
|
|
785
|
-
return send(event, Buffer.from(arrayBuffer), val.type);
|
|
786
|
-
});
|
|
787
|
-
if (val instanceof Error) throw createError(val);
|
|
788
|
-
if (typeof val.end === "function") return true;
|
|
789
|
-
}
|
|
790
|
-
const valType = typeof val;
|
|
791
|
-
if (valType === "string") return send(event, val, MIMES.html);
|
|
792
|
-
if (valType === "object" || valType === "boolean" || valType === "number") return send(event, JSON.stringify(val, void 0, jsonSpace), MIMES.json);
|
|
793
|
-
if (valType === "bigint") return send(event, val.toString(), MIMES.json);
|
|
794
|
-
throw createError({
|
|
795
|
-
statusCode: 500,
|
|
796
|
-
statusMessage: `[h3] Cannot send ${valType} as response.`
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
function cachedFn(fn) {
|
|
800
|
-
let cache;
|
|
801
|
-
return () => {
|
|
802
|
-
if (!cache) cache = fn();
|
|
803
|
-
return cache;
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
function websocketOptions(evResolver, appOptions) {
|
|
807
|
-
return {
|
|
808
|
-
...appOptions.websocket,
|
|
809
|
-
async resolve(info) {
|
|
810
|
-
const url = info.request?.url || info.url || "/";
|
|
811
|
-
const { pathname } = typeof url === "string" ? parseURL(url) : url;
|
|
812
|
-
return (await evResolver(pathname))?.handler?.__websocket__ || {};
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
function fromNodeMiddleware(handler) {
|
|
817
|
-
if (isEventHandler(handler)) return handler;
|
|
818
|
-
if (typeof handler !== "function") throw new TypeError("Invalid handler. It should be a function:", handler);
|
|
819
|
-
return eventHandler((event) => {
|
|
820
|
-
return callNodeListener(handler, event.node.req, event.node.res);
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
function toNodeListener(app) {
|
|
824
|
-
const toNodeHandle = async function(req, res) {
|
|
825
|
-
const event = createEvent(req, res);
|
|
826
|
-
try {
|
|
827
|
-
await app.handler(event);
|
|
828
|
-
} catch (_error) {
|
|
829
|
-
const error = createError(_error);
|
|
830
|
-
if (!isError(_error)) error.unhandled = true;
|
|
831
|
-
setResponseStatus(event, error.statusCode, error.statusMessage);
|
|
832
|
-
if (app.options.onError) await app.options.onError(error, event);
|
|
833
|
-
if (event.handled) return;
|
|
834
|
-
if (error.unhandled || error.fatal) console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
|
|
835
|
-
if (app.options.onBeforeResponse && !event._onBeforeResponseCalled) await app.options.onBeforeResponse(event, { body: error });
|
|
836
|
-
await sendError(event, error, !!app.options.debug);
|
|
837
|
-
if (app.options.onAfterResponse && !event._onAfterResponseCalled) await app.options.onAfterResponse(event, { body: error });
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
return toNodeHandle;
|
|
841
|
-
}
|
|
842
|
-
function callNodeListener(handler, req, res) {
|
|
843
|
-
const isMiddleware = handler.length > 2;
|
|
844
|
-
return new Promise((resolve, reject) => {
|
|
845
|
-
const next = (err) => {
|
|
846
|
-
if (isMiddleware) {
|
|
847
|
-
res.off("close", next);
|
|
848
|
-
res.off("error", next);
|
|
849
|
-
}
|
|
850
|
-
return err ? reject(createError(err)) : resolve(void 0);
|
|
851
|
-
};
|
|
852
|
-
try {
|
|
853
|
-
const returned = handler(req, res, next);
|
|
854
|
-
if (isMiddleware && returned === void 0) {
|
|
855
|
-
res.once("close", next);
|
|
856
|
-
res.once("error", next);
|
|
857
|
-
} else resolve(returned);
|
|
858
|
-
} catch (error) {
|
|
859
|
-
next(error);
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
//#endregion
|
|
865
|
-
//#region ../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.cjs
|
|
866
|
-
var require_ansis = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.cjs": ((exports, module) => {
|
|
867
|
-
let e, t, r, { defineProperty: l, setPrototypeOf: n, create: o, keys: s } = Object, i = "", { round: c, max: a$1 } = Math, p = (e$1) => {
|
|
868
|
-
let t$1 = /([a-f\d]{3,6})/i.exec(e$1)?.[1], r$2 = t$1?.length, l$1 = parseInt(6 ^ r$2 ? 3 ^ r$2 ? "0" : t$1[0] + t$1[0] + t$1[1] + t$1[1] + t$1[2] + t$1[2] : t$1, 16);
|
|
869
|
-
return [
|
|
870
|
-
l$1 >> 16 & 255,
|
|
871
|
-
l$1 >> 8 & 255,
|
|
872
|
-
255 & l$1
|
|
873
|
-
];
|
|
874
|
-
}, u = (e$1, t$1, r$2) => e$1 ^ t$1 || t$1 ^ r$2 ? 16 + 36 * c(e$1 / 51) + 6 * c(t$1 / 51) + c(r$2 / 51) : 8 > e$1 ? 16 : e$1 > 248 ? 231 : c(24 * (e$1 - 8) / 247) + 232, d = (e$1) => {
|
|
875
|
-
let t$1, r$2, l$1, n$1, o$1;
|
|
876
|
-
return 8 > e$1 ? 30 + e$1 : 16 > e$1 ? e$1 - 8 + 90 : (232 > e$1 ? (o$1 = (e$1 -= 16) % 36, t$1 = (e$1 / 36 | 0) / 5, r$2 = (o$1 / 6 | 0) / 5, l$1 = o$1 % 6 / 5) : t$1 = r$2 = l$1 = (10 * (e$1 - 232) + 8) / 255, n$1 = 2 * a$1(t$1, r$2, l$1), n$1 ? 30 + (c(l$1) << 2 | c(r$2) << 1 | c(t$1)) + (2 ^ n$1 ? 0 : 60) : 30);
|
|
877
|
-
}, f = (() => {
|
|
878
|
-
let r$2 = (e$1) => o$1.some(((t$1) => e$1.test(t$1))), l$1 = globalThis, n$1 = l$1.process ?? {}, o$1 = n$1.argv ?? [], i$1 = n$1.env ?? {}, c$1 = -1;
|
|
879
|
-
try {
|
|
880
|
-
e = "," + s(i$1).join(",");
|
|
881
|
-
} catch (e$1) {
|
|
882
|
-
i$1 = {}, c$1 = 0;
|
|
883
|
-
}
|
|
884
|
-
let a$2 = "FORCE_COLOR", p$1 = {
|
|
885
|
-
false: 0,
|
|
886
|
-
0: 0,
|
|
887
|
-
1: 1,
|
|
888
|
-
2: 2,
|
|
889
|
-
3: 3
|
|
890
|
-
}[i$1[a$2]] ?? -1, u$1 = a$2 in i$1 && p$1 || r$2(/^--color=?(true|always)?$/);
|
|
891
|
-
return u$1 && (c$1 = p$1), ~c$1 || (c$1 = ((r$3, l$2, n$2) => (t = r$3.TERM, {
|
|
892
|
-
"24bit": 3,
|
|
893
|
-
truecolor: 3,
|
|
894
|
-
ansi256: 2,
|
|
895
|
-
ansi: 1
|
|
896
|
-
}[r$3.COLORTERM] || (r$3.CI ? /,GITHUB/.test(e) ? 3 : 1 : l$2 && "dumb" !== t ? n$2 ? 3 : /-256/.test(t) ? 2 : 1 : 0)))(i$1, !!i$1.PM2_HOME || i$1.NEXT_RUNTIME?.includes("edge") || !!n$1.stdout?.isTTY, "win32" === n$1.platform)), !p$1 || i$1.NO_COLOR || r$2(/^--(no-color|color=(false|never))$/) ? 0 : l$1.window?.chrome || u$1 && !c$1 ? 3 : c$1;
|
|
897
|
-
})(), g = {
|
|
898
|
-
open: i,
|
|
899
|
-
close: i
|
|
900
|
-
}, h = 39, b = 49, O = {}, m = ({ p: e$1 }, { open: t$1, close: l$1 }) => {
|
|
901
|
-
let o$1 = (e$2, ...r$2) => {
|
|
902
|
-
if (!e$2) {
|
|
903
|
-
if (t$1 && t$1 === l$1) return t$1;
|
|
904
|
-
if ((e$2 ?? i) === i) return i;
|
|
905
|
-
}
|
|
906
|
-
let n$1, s$2 = e$2.raw ? String.raw({ raw: e$2 }, ...r$2) : i + e$2, c$2 = o$1.p, a$2 = c$2.o, p$1 = c$2.c;
|
|
907
|
-
if (s$2.includes("\x1B")) for (; c$2; c$2 = c$2.p) {
|
|
908
|
-
let { open: e$3, close: t$2 } = c$2, r$3 = t$2.length, l$2 = i, o$2 = 0;
|
|
909
|
-
if (r$3) for (; ~(n$1 = s$2.indexOf(t$2, o$2)); o$2 = n$1 + r$3) l$2 += s$2.slice(o$2, n$1) + e$3;
|
|
910
|
-
s$2 = l$2 + s$2.slice(o$2);
|
|
911
|
-
}
|
|
912
|
-
return a$2 + (s$2.includes("\n") ? s$2.replace(/(\r?\n)/g, p$1 + "$1" + a$2) : s$2) + p$1;
|
|
913
|
-
}, s$1 = t$1, c$1 = l$1;
|
|
914
|
-
return e$1 && (s$1 = e$1.o + t$1, c$1 = l$1 + e$1.c), n(o$1, r), o$1.p = {
|
|
915
|
-
open: t$1,
|
|
916
|
-
close: l$1,
|
|
917
|
-
o: s$1,
|
|
918
|
-
c: c$1,
|
|
919
|
-
p: e$1
|
|
920
|
-
}, o$1.open = s$1, o$1.close = c$1, o$1;
|
|
921
|
-
};
|
|
922
|
-
const w = new function e$1(t$1 = f) {
|
|
923
|
-
let s$1 = {
|
|
924
|
-
Ansis: e$1,
|
|
925
|
-
level: t$1,
|
|
926
|
-
isSupported: () => a$2,
|
|
927
|
-
strip: (e$2) => e$2.replace(/[][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, i),
|
|
928
|
-
extend(e$2) {
|
|
929
|
-
for (let t$2 in e$2) {
|
|
930
|
-
let r$2 = e$2[t$2], l$1 = (typeof r$2)[0];
|
|
931
|
-
"s" === l$1 ? (c$1(t$2, T(...p(r$2))), c$1(_(t$2), v(...p(r$2)))) : c$1(t$2, r$2, "f" === l$1);
|
|
932
|
-
}
|
|
933
|
-
return r = o({}, O), n(s$1, r), s$1;
|
|
934
|
-
}
|
|
935
|
-
}, c$1 = (e$2, t$2, r$2) => {
|
|
936
|
-
O[e$2] = { get() {
|
|
937
|
-
let n$1 = r$2 ? (...e$3) => m(this, t$2(...e$3)) : m(this, t$2);
|
|
938
|
-
return l(this, e$2, { value: n$1 }), n$1;
|
|
939
|
-
} };
|
|
940
|
-
}, a$2 = t$1 > 0, w$1 = (e$2, t$2) => a$2 ? {
|
|
941
|
-
open: `[${e$2}m`,
|
|
942
|
-
close: `[${t$2}m`
|
|
943
|
-
} : g, y = (e$2) => (t$2) => e$2(...p(t$2)), R = (e$2, t$2) => (r$2, l$1, n$1) => w$1(`${e$2}8;2;${r$2};${l$1};${n$1}`, t$2), $ = (e$2, t$2) => (r$2, l$1, n$1) => w$1(((e$3, t$3, r$3) => d(u(e$3, t$3, r$3)))(r$2, l$1, n$1) + e$2, t$2), x = (e$2) => (t$2, r$2, l$1) => e$2(u(t$2, r$2, l$1)), T = R(3, h), v = R(4, b), C = (e$2) => w$1("38;5;" + e$2, h), E = (e$2) => w$1("48;5;" + e$2, b);
|
|
944
|
-
2 === t$1 ? (T = x(C), v = x(E)) : 1 === t$1 && (T = $(0, h), v = $(10, b), C = (e$2) => w$1(d(e$2), h), E = (e$2) => w$1(d(e$2) + 10, b));
|
|
945
|
-
let M, I = {
|
|
946
|
-
fg: C,
|
|
947
|
-
bg: E,
|
|
948
|
-
rgb: T,
|
|
949
|
-
bgRgb: v,
|
|
950
|
-
hex: y(T),
|
|
951
|
-
bgHex: y(v),
|
|
952
|
-
visible: g,
|
|
953
|
-
reset: w$1(0, 0),
|
|
954
|
-
bold: w$1(1, 22),
|
|
955
|
-
dim: w$1(2, 22),
|
|
956
|
-
italic: w$1(3, 23),
|
|
957
|
-
underline: w$1(4, 24),
|
|
958
|
-
inverse: w$1(7, 27),
|
|
959
|
-
hidden: w$1(8, 28),
|
|
960
|
-
strikethrough: w$1(9, 29)
|
|
961
|
-
}, _ = (e$2) => "bg" + e$2[0].toUpperCase() + e$2.slice(1), k = "Bright";
|
|
962
|
-
return "black,red,green,yellow,blue,magenta,cyan,white,gray".split(",").map(((e$2, t$2) => {
|
|
963
|
-
M = _(e$2), 8 > t$2 ? (I[e$2 + k] = w$1(90 + t$2, h), I[M + k] = w$1(100 + t$2, b)) : t$2 = 60, I[e$2] = w$1(30 + t$2, h), I[M] = w$1(40 + t$2, b);
|
|
964
|
-
})), s$1.extend(I);
|
|
965
|
-
}();
|
|
966
|
-
module.exports = w, w.default = w;
|
|
967
|
-
}) });
|
|
968
|
-
|
|
969
|
-
//#endregion
|
|
970
|
-
//#region ../../node_modules/.pnpm/ansis@4.2.0/node_modules/ansis/index.mjs
|
|
971
|
-
var import_ansis = /* @__PURE__ */ __toESM(require_ansis(), 1);
|
|
972
|
-
var ansis_default = import_ansis.default;
|
|
973
|
-
const { Ansis, fg, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
|
|
974
|
-
|
|
975
|
-
//#endregion
|
|
976
|
-
//#region ../../node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
|
|
977
|
-
const unsafePorts = /* @__PURE__ */ new Set([
|
|
978
|
-
1,
|
|
979
|
-
7,
|
|
980
|
-
9,
|
|
981
|
-
11,
|
|
982
|
-
13,
|
|
983
|
-
15,
|
|
984
|
-
17,
|
|
985
|
-
19,
|
|
986
|
-
20,
|
|
987
|
-
21,
|
|
988
|
-
22,
|
|
989
|
-
23,
|
|
990
|
-
25,
|
|
991
|
-
37,
|
|
992
|
-
42,
|
|
993
|
-
43,
|
|
994
|
-
53,
|
|
995
|
-
69,
|
|
996
|
-
77,
|
|
997
|
-
79,
|
|
998
|
-
87,
|
|
999
|
-
95,
|
|
1000
|
-
101,
|
|
1001
|
-
102,
|
|
1002
|
-
103,
|
|
1003
|
-
104,
|
|
1004
|
-
109,
|
|
1005
|
-
110,
|
|
1006
|
-
111,
|
|
1007
|
-
113,
|
|
1008
|
-
115,
|
|
1009
|
-
117,
|
|
1010
|
-
119,
|
|
1011
|
-
123,
|
|
1012
|
-
135,
|
|
1013
|
-
137,
|
|
1014
|
-
139,
|
|
1015
|
-
143,
|
|
1016
|
-
161,
|
|
1017
|
-
179,
|
|
1018
|
-
389,
|
|
1019
|
-
427,
|
|
1020
|
-
465,
|
|
1021
|
-
512,
|
|
1022
|
-
513,
|
|
1023
|
-
514,
|
|
1024
|
-
515,
|
|
1025
|
-
526,
|
|
1026
|
-
530,
|
|
1027
|
-
531,
|
|
1028
|
-
532,
|
|
1029
|
-
540,
|
|
1030
|
-
548,
|
|
1031
|
-
554,
|
|
1032
|
-
556,
|
|
1033
|
-
563,
|
|
1034
|
-
587,
|
|
1035
|
-
601,
|
|
1036
|
-
636,
|
|
1037
|
-
989,
|
|
1038
|
-
990,
|
|
1039
|
-
993,
|
|
1040
|
-
995,
|
|
1041
|
-
1719,
|
|
1042
|
-
1720,
|
|
1043
|
-
1723,
|
|
1044
|
-
2049,
|
|
1045
|
-
3659,
|
|
1046
|
-
4045,
|
|
1047
|
-
5060,
|
|
1048
|
-
5061,
|
|
1049
|
-
6e3,
|
|
1050
|
-
6566,
|
|
1051
|
-
6665,
|
|
1052
|
-
6666,
|
|
1053
|
-
6667,
|
|
1054
|
-
6668,
|
|
1055
|
-
6669,
|
|
1056
|
-
6697,
|
|
1057
|
-
10080
|
|
1058
|
-
]);
|
|
1059
|
-
function isUnsafePort(port) {
|
|
1060
|
-
return unsafePorts.has(port);
|
|
1061
|
-
}
|
|
1062
|
-
function isSafePort(port) {
|
|
1063
|
-
return !isUnsafePort(port);
|
|
1064
|
-
}
|
|
1065
|
-
var GetPortError = class extends Error {
|
|
1066
|
-
constructor(message, opts) {
|
|
1067
|
-
super(message, opts);
|
|
1068
|
-
this.message = message;
|
|
1069
|
-
}
|
|
1070
|
-
name = "GetPortError";
|
|
1071
|
-
};
|
|
1072
|
-
function _log(verbose, message) {
|
|
1073
|
-
if (verbose) console.log(`[get-port] ${message}`);
|
|
1074
|
-
}
|
|
1075
|
-
function _generateRange(from, to) {
|
|
1076
|
-
if (to < from) return [];
|
|
1077
|
-
const r$2 = [];
|
|
1078
|
-
for (let index = from; index <= to; index++) r$2.push(index);
|
|
1079
|
-
return r$2;
|
|
1080
|
-
}
|
|
1081
|
-
function _tryPort(port, host) {
|
|
1082
|
-
return new Promise((resolve) => {
|
|
1083
|
-
const server = createServer();
|
|
1084
|
-
server.unref();
|
|
1085
|
-
server.on("error", () => {
|
|
1086
|
-
resolve(false);
|
|
1087
|
-
});
|
|
1088
|
-
server.listen({
|
|
1089
|
-
port,
|
|
1090
|
-
host
|
|
1091
|
-
}, () => {
|
|
1092
|
-
const { port: port2 } = server.address();
|
|
1093
|
-
server.close(() => {
|
|
1094
|
-
resolve(isSafePort(port2) && port2);
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
function _getLocalHosts(additional) {
|
|
1100
|
-
const hosts = new Set(additional);
|
|
1101
|
-
for (const _interface of Object.values(networkInterfaces())) for (const config of _interface || []) if (config.address && !config.internal && !config.address.startsWith("fe80::") && !config.address.startsWith("169.254")) hosts.add(config.address);
|
|
1102
|
-
return [...hosts];
|
|
1103
|
-
}
|
|
1104
|
-
async function _findPort(ports, host) {
|
|
1105
|
-
for (const port of ports) {
|
|
1106
|
-
const r$2 = await _tryPort(port, host);
|
|
1107
|
-
if (r$2) return r$2;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
function _fmtOnHost(hostname) {
|
|
1111
|
-
return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
|
|
1112
|
-
}
|
|
1113
|
-
const HOSTNAME_RE = /^(?!-)[\d.:A-Za-z-]{1,63}(?<!-)$/;
|
|
1114
|
-
function _validateHostname(hostname, _public, verbose) {
|
|
1115
|
-
if (hostname && !HOSTNAME_RE.test(hostname)) {
|
|
1116
|
-
const fallbackHost = _public ? "0.0.0.0" : "127.0.0.1";
|
|
1117
|
-
_log(verbose, `Invalid hostname: ${JSON.stringify(hostname)}. Using ${JSON.stringify(fallbackHost)} as fallback.`);
|
|
1118
|
-
return fallbackHost;
|
|
1119
|
-
}
|
|
1120
|
-
return hostname;
|
|
1121
|
-
}
|
|
1122
|
-
async function getPort(_userOptions = {}) {
|
|
1123
|
-
if (typeof _userOptions === "number" || typeof _userOptions === "string") _userOptions = { port: Number.parseInt(_userOptions + "") || 0 };
|
|
1124
|
-
const _port = Number(_userOptions.port ?? process.env.PORT);
|
|
1125
|
-
const _userSpecifiedAnyPort = Boolean(_userOptions.port || _userOptions.ports?.length || _userOptions.portRange?.length);
|
|
1126
|
-
const options = {
|
|
1127
|
-
random: _port === 0,
|
|
1128
|
-
ports: [],
|
|
1129
|
-
portRange: [],
|
|
1130
|
-
alternativePortRange: _userSpecifiedAnyPort ? [] : [3e3, 3100],
|
|
1131
|
-
verbose: false,
|
|
1132
|
-
..._userOptions,
|
|
1133
|
-
port: _port,
|
|
1134
|
-
host: _validateHostname(_userOptions.host ?? process.env.HOST, _userOptions.public, _userOptions.verbose)
|
|
1135
|
-
};
|
|
1136
|
-
if (options.random && !_userSpecifiedAnyPort) return getRandomPort(options.host);
|
|
1137
|
-
const portsToCheck = [
|
|
1138
|
-
options.port,
|
|
1139
|
-
...options.ports,
|
|
1140
|
-
..._generateRange(...options.portRange)
|
|
1141
|
-
].filter((port) => {
|
|
1142
|
-
if (!port) return false;
|
|
1143
|
-
if (!isSafePort(port)) {
|
|
1144
|
-
_log(options.verbose, `Ignoring unsafe port: ${port}`);
|
|
1145
|
-
return false;
|
|
1146
|
-
}
|
|
1147
|
-
return true;
|
|
1148
|
-
});
|
|
1149
|
-
if (portsToCheck.length === 0) portsToCheck.push(3e3);
|
|
1150
|
-
let availablePort = await _findPort(portsToCheck, options.host);
|
|
1151
|
-
if (!availablePort && options.alternativePortRange.length > 0) {
|
|
1152
|
-
availablePort = await _findPort(_generateRange(...options.alternativePortRange), options.host);
|
|
1153
|
-
if (portsToCheck.length > 0) {
|
|
1154
|
-
let message = `Unable to find an available port (tried ${portsToCheck.join("-")} ${_fmtOnHost(options.host)}).`;
|
|
1155
|
-
if (availablePort) message += ` Using alternative port ${availablePort}.`;
|
|
1156
|
-
_log(options.verbose, message);
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
if (!availablePort && _userOptions.random !== false) {
|
|
1160
|
-
availablePort = await getRandomPort(options.host);
|
|
1161
|
-
if (availablePort) _log(options.verbose, `Using random port ${availablePort}`);
|
|
1162
|
-
}
|
|
1163
|
-
if (!availablePort) {
|
|
1164
|
-
const triedRanges = [
|
|
1165
|
-
options.port,
|
|
1166
|
-
options.portRange.join("-"),
|
|
1167
|
-
options.alternativePortRange.join("-")
|
|
1168
|
-
].filter(Boolean).join(", ");
|
|
1169
|
-
throw new GetPortError(`Unable to find an available port ${_fmtOnHost(options.host)} (tried ${triedRanges})`);
|
|
1170
|
-
}
|
|
1171
|
-
return availablePort;
|
|
1172
|
-
}
|
|
1173
|
-
async function getRandomPort(host) {
|
|
1174
|
-
const port = await checkPort(0, host);
|
|
1175
|
-
if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
|
|
1176
|
-
return port;
|
|
1177
|
-
}
|
|
1178
|
-
async function checkPort(port, host = process.env.HOST, verbose) {
|
|
1179
|
-
if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
|
|
1180
|
-
if (!Array.isArray(host)) return _tryPort(port, host);
|
|
1181
|
-
for (const _host of host) {
|
|
1182
|
-
const _port = await _tryPort(port, _host);
|
|
1183
|
-
if (_port === false) {
|
|
1184
|
-
if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
|
|
1185
|
-
return false;
|
|
1186
|
-
}
|
|
1187
|
-
if (port === 0 && _port !== 0) port = _port;
|
|
1188
|
-
}
|
|
1189
|
-
return port;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
//#endregion
|
|
1193
|
-
//#region src/node/constants.ts
|
|
1194
|
-
const MARK_CHECK = ansis_default.green("✔");
|
|
1195
|
-
const MARK_INFO = ansis_default.blue("ℹ");
|
|
1196
|
-
const MARK_ERROR = ansis_default.red("✖");
|
|
1197
|
-
const MARK_NODE = "⬢";
|
|
1198
|
-
|
|
1199
|
-
//#endregion
|
|
1200
|
-
//#region src/node/ws.ts
|
|
1201
|
-
async function createWsServer(options) {
|
|
1202
|
-
const rpcHost = options.context.rpc;
|
|
1203
|
-
const port = options.portWebSocket ?? await getPort({
|
|
1204
|
-
port: 7812,
|
|
1205
|
-
random: true
|
|
1206
|
-
});
|
|
1207
|
-
const wsClients = /* @__PURE__ */ new Set();
|
|
1208
|
-
const preset = createWsRpcPreset({
|
|
1209
|
-
port,
|
|
1210
|
-
onConnected: (ws) => {
|
|
1211
|
-
wsClients.add(ws);
|
|
1212
|
-
console.log(ansis_default.green`${MARK_CHECK} Websocket client connected`);
|
|
1213
|
-
},
|
|
1214
|
-
onDisconnected: (ws) => {
|
|
1215
|
-
wsClients.delete(ws);
|
|
1216
|
-
console.log(ansis_default.red`${MARK_CHECK} Websocket client disconnected`);
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
const rpc = createRpcServer(rpcHost.functions, {
|
|
1220
|
-
preset,
|
|
1221
|
-
rpcOptions: { onError(error, name) {
|
|
1222
|
-
console.error(ansis_default.red`⬢ RPC error on executing "${ansis_default.bold(name)}":`);
|
|
1223
|
-
console.error(error);
|
|
1224
|
-
throw error;
|
|
1225
|
-
} }
|
|
1226
|
-
});
|
|
1227
|
-
const getMetadata = async () => {
|
|
1228
|
-
return {
|
|
1229
|
-
backend: "websocket",
|
|
1230
|
-
websocket: port
|
|
1231
|
-
};
|
|
1232
|
-
};
|
|
1233
|
-
return {
|
|
1234
|
-
port,
|
|
1235
|
-
rpc,
|
|
1236
|
-
functions: rpcHost,
|
|
1237
|
-
getMetadata
|
|
1238
|
-
};
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
//#endregion
|
|
1242
|
-
//#region src/node/server.ts
|
|
1243
|
-
async function createDevToolsMiddleware(options) {
|
|
1244
|
-
const app = createApp();
|
|
1245
|
-
const { rpc, getMetadata } = await createWsServer(options);
|
|
1246
|
-
app.use("/api/connection.json", eventHandler(async (event) => {
|
|
1247
|
-
event.node.res.setHeader("Content-Type", "application/json");
|
|
1248
|
-
return event.node.res.end(JSON.stringify(await getMetadata()));
|
|
1249
|
-
}));
|
|
1250
|
-
app.use(fromNodeMiddleware(sirv(dirClientStandalone, {
|
|
1251
|
-
dev: true,
|
|
1252
|
-
single: true
|
|
1253
|
-
})));
|
|
1254
|
-
return {
|
|
1255
|
-
h3: app,
|
|
1256
|
-
middleware: toNodeListener(app),
|
|
1257
|
-
rpc
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
//#endregion
|
|
1262
|
-
export { MARK_NODE, ansis_default, createApp, createDevToolsContext, createDevToolsMiddleware, eventHandler, getPort, sendRedirect, toNodeListener };
|