react-router-hono-server 2.16.0 → 2.17.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -490,6 +490,10 @@ You can add additional Hono middleware with the `configure` function. If you do
490
490
 
491
491
  The `configure` function can be async. So, make sure to `await createHonoServer()`.
492
492
 
493
+ > NB: If you import some shared code in your server file (or middleware), Vite will code split the file (your server code will be in a separate chunk, re-exported as default in `build/server/index.js`).
494
+ >
495
+ > In this situation, if you `await createHonoServer()` it will error with `Detected unsettled top-level await`. Just remove the `await` and it will work fine.
496
+
493
497
  If you want to set up the React Router `AppLoadContext`, pass in a function to `getLoadContext`.
494
498
 
495
499
  Modify the `AppLoadContext` interface used in your app.
@@ -1,15 +1,18 @@
1
+ import {
2
+ serveStatic
3
+ } from "../chunk-QDN4PJRA.js";
1
4
  import {
2
5
  bindIncomingRequestSocketInfo,
3
6
  createGetLoadContext,
4
7
  getBuildMode,
5
8
  importBuild
6
- } from "../chunk-IZYOBD55.js";
9
+ } from "../chunk-ZGIYBMNC.js";
7
10
  import {
8
11
  cache
9
12
  } from "../chunk-YI5FED4X.js";
13
+ import "../chunk-JSBRDJBE.js";
10
14
 
11
15
  // src/adapters/aws-lambda.ts
12
- import { serveStatic } from "@hono/node-server/serve-static";
13
16
  import { Hono } from "hono";
14
17
  import { handle, streamHandle } from "hono/aws-lambda";
15
18
  import { createMiddleware } from "hono/factory";
@@ -6,10 +6,11 @@ import {
6
6
  getBuildMode,
7
7
  importBuild,
8
8
  patchUpgradeListener
9
- } from "../chunk-IZYOBD55.js";
9
+ } from "../chunk-ZGIYBMNC.js";
10
10
  import {
11
11
  cache
12
12
  } from "../chunk-YI5FED4X.js";
13
+ import "../chunk-JSBRDJBE.js";
13
14
 
14
15
  // src/adapters/bun.ts
15
16
  import { Hono } from "hono";
@@ -18,6 +19,7 @@ import { createMiddleware } from "hono/factory";
18
19
  import { logger } from "hono/logger";
19
20
  import { createRequestHandler } from "react-router";
20
21
  async function createHonoServer(options) {
22
+ const build = await importBuild();
21
23
  const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
22
24
  const mergedOptions = {
23
25
  ...options,
@@ -65,8 +67,7 @@ async function createHonoServer(options) {
65
67
  const reactRouterApp = new Hono({
66
68
  strict: false
67
69
  });
68
- reactRouterApp.use(async (c, next) => {
69
- const build = await importBuild();
70
+ reactRouterApp.use((c, next) => {
70
71
  return createMiddleware(async (c2) => {
71
72
  const requestHandler = createRequestHandler(build, mode);
72
73
  const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
@@ -3,10 +3,11 @@ import {
3
3
  createGetLoadContext,
4
4
  getBuildMode,
5
5
  importBuild
6
- } from "../chunk-IZYOBD55.js";
6
+ } from "../chunk-ZGIYBMNC.js";
7
7
  import {
8
8
  cache
9
9
  } from "../chunk-YI5FED4X.js";
10
+ import "../chunk-JSBRDJBE.js";
10
11
 
11
12
  // src/adapters/cloudflare.ts
12
13
  import { Hono } from "hono";
@@ -39,7 +40,7 @@ async function createHonoServer(options) {
39
40
  serveCloudflareAssets()
40
41
  );
41
42
  } else {
42
- const { serveStatic } = await import("@hono/node-server/serve-static");
43
+ const { serveStatic } = await import("../serve-static-6NLY75NK.js");
43
44
  app.use(
44
45
  "*",
45
46
  cache(60 * 60),
@@ -1,3 +1,9 @@
1
+ import {
2
+ serve
3
+ } from "../chunk-OKB2FS67.js";
4
+ import {
5
+ serveStatic
6
+ } from "../chunk-QDN4PJRA.js";
1
7
  import {
2
8
  bindIncomingRequestSocketInfo,
3
9
  cleanUpgradeListeners,
@@ -6,19 +12,22 @@ import {
6
12
  getBuildMode,
7
13
  importBuild,
8
14
  patchUpgradeListener
9
- } from "../chunk-IZYOBD55.js";
15
+ } from "../chunk-ZGIYBMNC.js";
10
16
  import {
11
17
  cache
12
18
  } from "../chunk-YI5FED4X.js";
19
+ import "../chunk-JSBRDJBE.js";
13
20
 
14
21
  // src/adapters/node.ts
15
- import { serve } from "@hono/node-server";
16
- import { serveStatic } from "@hono/node-server/serve-static";
17
22
  import { Hono } from "hono";
18
23
  import { createMiddleware } from "hono/factory";
19
24
  import { logger } from "hono/logger";
20
25
  import { createRequestHandler } from "react-router";
21
26
  async function createHonoServer(options) {
27
+ if (!options?.listeningListener) {
28
+ console.time("\u{1F3CE}\uFE0F Server started in");
29
+ }
30
+ const build = await importBuild();
22
31
  const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
23
32
  const mergedOptions = {
24
33
  ...options,
@@ -28,6 +37,7 @@ async function createHonoServer(options) {
28
37
  if (basename !== "/") {
29
38
  console.log(`\u{1F517} http://127.0.0.1:${info.port}${basename}`);
30
39
  }
40
+ console.timeEnd("\u{1F3CE}\uFE0F Server started in");
31
41
  }),
32
42
  port: options?.port || Number(process.env.PORT) || 3e3,
33
43
  defaultLogger: options?.defaultLogger ?? true,
@@ -68,8 +78,7 @@ async function createHonoServer(options) {
68
78
  const reactRouterApp = new Hono({
69
79
  strict: false
70
80
  });
71
- reactRouterApp.use(async (c, next) => {
72
- const build = await importBuild();
81
+ reactRouterApp.use((c, next) => {
73
82
  return createMiddleware(async (c2) => {
74
83
  const requestHandler = createRequestHandler(build, mode);
75
84
  const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
@@ -0,0 +1,30 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ export {
28
+ __commonJS,
29
+ __toESM
30
+ };
@@ -0,0 +1,483 @@
1
+ // node_modules/.pnpm/@hono+node-server@1.14.1_hono@4.8.5/node_modules/@hono/node-server/dist/index.mjs
2
+ import { createServer as createServerHTTP } from "http";
3
+ import { Http2ServerRequest } from "http2";
4
+ import { Readable } from "stream";
5
+ import crypto from "crypto";
6
+ var RequestError = class extends Error {
7
+ static name = "RequestError";
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ }
11
+ };
12
+ var toRequestError = (e) => {
13
+ if (e instanceof RequestError) {
14
+ return e;
15
+ }
16
+ return new RequestError(e.message, { cause: e });
17
+ };
18
+ var GlobalRequest = global.Request;
19
+ var Request = class extends GlobalRequest {
20
+ constructor(input, options) {
21
+ if (typeof input === "object" && getRequestCache in input) {
22
+ input = input[getRequestCache]();
23
+ }
24
+ if (typeof options?.body?.getReader !== "undefined") {
25
+ ;
26
+ options.duplex ??= "half";
27
+ }
28
+ super(input, options);
29
+ }
30
+ };
31
+ var newRequestFromIncoming = (method, url, incoming, abortController) => {
32
+ const headerRecord = [];
33
+ const rawHeaders = incoming.rawHeaders;
34
+ for (let i = 0; i < rawHeaders.length; i += 2) {
35
+ const { [i]: key, [i + 1]: value } = rawHeaders;
36
+ if (key.charCodeAt(0) !== /*:*/
37
+ 58) {
38
+ headerRecord.push([key, value]);
39
+ }
40
+ }
41
+ const init = {
42
+ method,
43
+ headers: headerRecord,
44
+ signal: abortController.signal
45
+ };
46
+ if (method === "TRACE") {
47
+ init.method = "GET";
48
+ const req = new Request(url, init);
49
+ Object.defineProperty(req, "method", {
50
+ get() {
51
+ return "TRACE";
52
+ }
53
+ });
54
+ return req;
55
+ }
56
+ if (!(method === "GET" || method === "HEAD")) {
57
+ if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
58
+ init.body = new ReadableStream({
59
+ start(controller) {
60
+ controller.enqueue(incoming.rawBody);
61
+ controller.close();
62
+ }
63
+ });
64
+ } else {
65
+ init.body = Readable.toWeb(incoming);
66
+ }
67
+ }
68
+ return new Request(url, init);
69
+ };
70
+ var getRequestCache = Symbol("getRequestCache");
71
+ var requestCache = Symbol("requestCache");
72
+ var incomingKey = Symbol("incomingKey");
73
+ var urlKey = Symbol("urlKey");
74
+ var abortControllerKey = Symbol("abortControllerKey");
75
+ var getAbortController = Symbol("getAbortController");
76
+ var requestPrototype = {
77
+ get method() {
78
+ return this[incomingKey].method || "GET";
79
+ },
80
+ get url() {
81
+ return this[urlKey];
82
+ },
83
+ [getAbortController]() {
84
+ this[getRequestCache]();
85
+ return this[abortControllerKey];
86
+ },
87
+ [getRequestCache]() {
88
+ this[abortControllerKey] ||= new AbortController();
89
+ return this[requestCache] ||= newRequestFromIncoming(
90
+ this.method,
91
+ this[urlKey],
92
+ this[incomingKey],
93
+ this[abortControllerKey]
94
+ );
95
+ }
96
+ };
97
+ [
98
+ "body",
99
+ "bodyUsed",
100
+ "cache",
101
+ "credentials",
102
+ "destination",
103
+ "headers",
104
+ "integrity",
105
+ "mode",
106
+ "redirect",
107
+ "referrer",
108
+ "referrerPolicy",
109
+ "signal",
110
+ "keepalive"
111
+ ].forEach((k) => {
112
+ Object.defineProperty(requestPrototype, k, {
113
+ get() {
114
+ return this[getRequestCache]()[k];
115
+ }
116
+ });
117
+ });
118
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
119
+ Object.defineProperty(requestPrototype, k, {
120
+ value: function() {
121
+ return this[getRequestCache]()[k]();
122
+ }
123
+ });
124
+ });
125
+ Object.setPrototypeOf(requestPrototype, Request.prototype);
126
+ var newRequest = (incoming, defaultHostname) => {
127
+ const req = Object.create(requestPrototype);
128
+ req[incomingKey] = incoming;
129
+ const incomingUrl = incoming.url || "";
130
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
131
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
132
+ if (incoming instanceof Http2ServerRequest) {
133
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
134
+ }
135
+ try {
136
+ const url2 = new URL(incomingUrl);
137
+ req[urlKey] = url2.href;
138
+ } catch (e) {
139
+ throw new RequestError("Invalid absolute URL", { cause: e });
140
+ }
141
+ return req;
142
+ }
143
+ const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
144
+ if (!host) {
145
+ throw new RequestError("Missing host header");
146
+ }
147
+ let scheme;
148
+ if (incoming instanceof Http2ServerRequest) {
149
+ scheme = incoming.scheme;
150
+ if (!(scheme === "http" || scheme === "https")) {
151
+ throw new RequestError("Unsupported scheme");
152
+ }
153
+ } else {
154
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
155
+ }
156
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
157
+ if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
158
+ throw new RequestError("Invalid host header");
159
+ }
160
+ req[urlKey] = url.href;
161
+ return req;
162
+ };
163
+ function writeFromReadableStream(stream, writable) {
164
+ if (stream.locked) {
165
+ throw new TypeError("ReadableStream is locked.");
166
+ } else if (writable.destroyed) {
167
+ stream.cancel();
168
+ return;
169
+ }
170
+ const reader = stream.getReader();
171
+ writable.on("close", cancel);
172
+ writable.on("error", cancel);
173
+ reader.read().then(flow, cancel);
174
+ return reader.closed.finally(() => {
175
+ writable.off("close", cancel);
176
+ writable.off("error", cancel);
177
+ });
178
+ function cancel(error) {
179
+ reader.cancel(error).catch(() => {
180
+ });
181
+ if (error) {
182
+ writable.destroy(error);
183
+ }
184
+ }
185
+ function onDrain() {
186
+ reader.read().then(flow, cancel);
187
+ }
188
+ function flow({ done, value }) {
189
+ try {
190
+ if (done) {
191
+ writable.end();
192
+ } else if (!writable.write(value)) {
193
+ writable.once("drain", onDrain);
194
+ } else {
195
+ return reader.read().then(flow, cancel);
196
+ }
197
+ } catch (e) {
198
+ cancel(e);
199
+ }
200
+ }
201
+ }
202
+ var buildOutgoingHttpHeaders = (headers) => {
203
+ const res = {};
204
+ if (!(headers instanceof Headers)) {
205
+ headers = new Headers(headers ?? void 0);
206
+ }
207
+ const cookies = [];
208
+ for (const [k, v] of headers) {
209
+ if (k === "set-cookie") {
210
+ cookies.push(v);
211
+ } else {
212
+ res[k] = v;
213
+ }
214
+ }
215
+ if (cookies.length > 0) {
216
+ res["set-cookie"] = cookies;
217
+ }
218
+ res["content-type"] ??= "text/plain; charset=UTF-8";
219
+ return res;
220
+ };
221
+ var responseCache = Symbol("responseCache");
222
+ var getResponseCache = Symbol("getResponseCache");
223
+ var cacheKey = Symbol("cache");
224
+ var GlobalResponse = global.Response;
225
+ var Response2 = class _Response {
226
+ #body;
227
+ #init;
228
+ [getResponseCache]() {
229
+ delete this[cacheKey];
230
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
231
+ }
232
+ constructor(body, init) {
233
+ this.#body = body;
234
+ if (init instanceof _Response) {
235
+ const cachedGlobalResponse = init[responseCache];
236
+ if (cachedGlobalResponse) {
237
+ this.#init = cachedGlobalResponse;
238
+ this[getResponseCache]();
239
+ return;
240
+ } else {
241
+ this.#init = init.#init;
242
+ }
243
+ } else {
244
+ this.#init = init;
245
+ }
246
+ if (typeof body === "string" || typeof body?.getReader !== "undefined") {
247
+ let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
248
+ if (headers instanceof Headers) {
249
+ headers = buildOutgoingHttpHeaders(headers);
250
+ }
251
+ ;
252
+ this[cacheKey] = [init?.status || 200, body, headers];
253
+ }
254
+ }
255
+ };
256
+ [
257
+ "body",
258
+ "bodyUsed",
259
+ "headers",
260
+ "ok",
261
+ "redirected",
262
+ "status",
263
+ "statusText",
264
+ "trailers",
265
+ "type",
266
+ "url"
267
+ ].forEach((k) => {
268
+ Object.defineProperty(Response2.prototype, k, {
269
+ get() {
270
+ return this[getResponseCache]()[k];
271
+ }
272
+ });
273
+ });
274
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
275
+ Object.defineProperty(Response2.prototype, k, {
276
+ value: function() {
277
+ return this[getResponseCache]()[k]();
278
+ }
279
+ });
280
+ });
281
+ Object.setPrototypeOf(Response2, GlobalResponse);
282
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
283
+ var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
284
+ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
285
+ );
286
+ if (!stateKey) {
287
+ console.warn("Failed to find Response internal state key");
288
+ }
289
+ function getInternalBody(response) {
290
+ if (!stateKey) {
291
+ return;
292
+ }
293
+ if (response instanceof Response2) {
294
+ response = response[getResponseCache]();
295
+ }
296
+ const state = response[stateKey];
297
+ return state && state.body || void 0;
298
+ }
299
+ var X_ALREADY_SENT = "x-hono-already-sent";
300
+ var webFetch = global.fetch;
301
+ if (typeof global.crypto === "undefined") {
302
+ global.crypto = crypto;
303
+ }
304
+ global.fetch = (info, init) => {
305
+ init = {
306
+ // Disable compression handling so people can return the result of a fetch
307
+ // directly in the loader without messing with the Content-Encoding header.
308
+ compress: false,
309
+ ...init
310
+ };
311
+ return webFetch(info, init);
312
+ };
313
+ var regBuffer = /^no$/i;
314
+ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
315
+ var handleRequestError = () => new Response(null, {
316
+ status: 400
317
+ });
318
+ var handleFetchError = (e) => new Response(null, {
319
+ status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
320
+ });
321
+ var handleResponseError = (e, outgoing) => {
322
+ const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
323
+ if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
324
+ console.info("The user aborted a request.");
325
+ } else {
326
+ console.error(e);
327
+ if (!outgoing.headersSent) {
328
+ outgoing.writeHead(500, { "Content-Type": "text/plain" });
329
+ }
330
+ outgoing.end(`Error: ${err.message}`);
331
+ outgoing.destroy(err);
332
+ }
333
+ };
334
+ var responseViaCache = (res, outgoing) => {
335
+ const [status, body, header] = res[cacheKey];
336
+ if (typeof body === "string") {
337
+ header["Content-Length"] = Buffer.byteLength(body);
338
+ outgoing.writeHead(status, header);
339
+ outgoing.end(body);
340
+ } else {
341
+ outgoing.writeHead(status, header);
342
+ return writeFromReadableStream(body, outgoing)?.catch(
343
+ (e) => handleResponseError(e, outgoing)
344
+ );
345
+ }
346
+ };
347
+ var responseViaResponseObject = async (res, outgoing, options = {}) => {
348
+ if (res instanceof Promise) {
349
+ if (options.errorHandler) {
350
+ try {
351
+ res = await res;
352
+ } catch (err) {
353
+ const errRes = await options.errorHandler(err);
354
+ if (!errRes) {
355
+ return;
356
+ }
357
+ res = errRes;
358
+ }
359
+ } else {
360
+ res = await res.catch(handleFetchError);
361
+ }
362
+ }
363
+ if (cacheKey in res) {
364
+ return responseViaCache(res, outgoing);
365
+ }
366
+ const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
367
+ const internalBody = getInternalBody(res);
368
+ if (internalBody) {
369
+ const { length, source, stream } = internalBody;
370
+ if (source instanceof Uint8Array && source.byteLength !== length) {
371
+ } else {
372
+ if (length) {
373
+ resHeaderRecord["content-length"] = length;
374
+ }
375
+ outgoing.writeHead(res.status, resHeaderRecord);
376
+ if (typeof source === "string" || source instanceof Uint8Array) {
377
+ outgoing.end(source);
378
+ } else if (source instanceof Blob) {
379
+ outgoing.end(new Uint8Array(await source.arrayBuffer()));
380
+ } else {
381
+ await writeFromReadableStream(stream, outgoing);
382
+ }
383
+ return;
384
+ }
385
+ }
386
+ if (res.body) {
387
+ const {
388
+ "transfer-encoding": transferEncoding,
389
+ "content-encoding": contentEncoding,
390
+ "content-length": contentLength,
391
+ "x-accel-buffering": accelBuffering,
392
+ "content-type": contentType
393
+ } = resHeaderRecord;
394
+ if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
395
+ accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
396
+ outgoing.writeHead(res.status, resHeaderRecord);
397
+ await writeFromReadableStream(res.body, outgoing);
398
+ } else {
399
+ const buffer = await res.arrayBuffer();
400
+ resHeaderRecord["content-length"] = buffer.byteLength;
401
+ outgoing.writeHead(res.status, resHeaderRecord);
402
+ outgoing.end(new Uint8Array(buffer));
403
+ }
404
+ } else if (resHeaderRecord[X_ALREADY_SENT]) {
405
+ } else {
406
+ outgoing.writeHead(res.status, resHeaderRecord);
407
+ outgoing.end();
408
+ }
409
+ };
410
+ var getRequestListener = (fetchCallback, options = {}) => {
411
+ if (options.overrideGlobalObjects !== false && global.Request !== Request) {
412
+ Object.defineProperty(global, "Request", {
413
+ value: Request
414
+ });
415
+ Object.defineProperty(global, "Response", {
416
+ value: Response2
417
+ });
418
+ }
419
+ return async (incoming, outgoing) => {
420
+ let res, req;
421
+ try {
422
+ req = newRequest(incoming, options.hostname);
423
+ outgoing.on("close", () => {
424
+ const abortController = req[abortControllerKey];
425
+ if (!abortController) {
426
+ return;
427
+ }
428
+ if (incoming.errored) {
429
+ req[abortControllerKey].abort(incoming.errored.toString());
430
+ } else if (!outgoing.writableFinished) {
431
+ req[abortControllerKey].abort("Client connection prematurely closed.");
432
+ }
433
+ });
434
+ res = fetchCallback(req, { incoming, outgoing });
435
+ if (cacheKey in res) {
436
+ return responseViaCache(res, outgoing);
437
+ }
438
+ } catch (e) {
439
+ if (!res) {
440
+ if (options.errorHandler) {
441
+ res = await options.errorHandler(req ? e : toRequestError(e));
442
+ if (!res) {
443
+ return;
444
+ }
445
+ } else if (!req) {
446
+ res = handleRequestError();
447
+ } else {
448
+ res = handleFetchError(e);
449
+ }
450
+ } else {
451
+ return handleResponseError(e, outgoing);
452
+ }
453
+ }
454
+ try {
455
+ return await responseViaResponseObject(res, outgoing, options);
456
+ } catch (e) {
457
+ return handleResponseError(e, outgoing);
458
+ }
459
+ };
460
+ };
461
+ var createAdaptorServer = (options) => {
462
+ const fetchCallback = options.fetch;
463
+ const requestListener = getRequestListener(fetchCallback, {
464
+ hostname: options.hostname,
465
+ overrideGlobalObjects: options.overrideGlobalObjects
466
+ });
467
+ const createServer = options.createServer || createServerHTTP;
468
+ const server = createServer(options.serverOptions || {}, requestListener);
469
+ return server;
470
+ };
471
+ var serve = (options, listeningListener) => {
472
+ const server = createAdaptorServer(options);
473
+ server.listen(options?.port ?? 3e3, options.hostname, () => {
474
+ const serverInfo = server.address();
475
+ listeningListener && listeningListener(serverInfo);
476
+ });
477
+ return server;
478
+ };
479
+
480
+ export {
481
+ getRequestListener,
482
+ serve
483
+ };