react-router-hono-server 2.17.0-next.2 → 2.17.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/dist/http.js CHANGED
@@ -1,5 +1,3 @@
1
- import "./chunk-JSBRDJBE.js";
2
-
3
1
  // src/http.ts
4
2
  function reactRouterRedirect(location) {
5
3
  return new Response(
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  cache
3
3
  } from "./chunk-YI5FED4X.js";
4
- import "./chunk-JSBRDJBE.js";
5
4
  export {
6
5
  cache
7
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router-hono-server",
3
- "version": "2.17.0-next.2",
3
+ "version": "2.17.0",
4
4
  "type": "module",
5
5
  "description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
6
6
  "publishConfig": {
@@ -75,9 +75,9 @@
75
75
  "homepage": "https://github.com/rphlmr/react-router-hono-server#readme",
76
76
  "dependencies": {
77
77
  "@drizzle-team/brocli": "^0.11.0",
78
- "@hono/node-server": "1.14.1",
79
- "@hono/node-ws": "1.2.0",
80
- "@hono/vite-dev-server": "0.20.0",
78
+ "@hono/node-server": "^1.18.0",
79
+ "@hono/node-ws": "^1.2.0",
80
+ "@hono/vite-dev-server": "^0.20.0",
81
81
  "hono": "^4.7.5"
82
82
  },
83
83
  "devDependencies": {
@@ -1,30 +0,0 @@
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
- };
@@ -1,483 +0,0 @@
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
- };
@@ -1,128 +0,0 @@
1
- // node_modules/.pnpm/@hono+node-server@1.14.1_hono@4.8.5/node_modules/@hono/node-server/dist/serve-static.mjs
2
- import { getFilePath, getFilePathWithoutDefaultDocument } from "hono/utils/filepath";
3
- import { getMimeType } from "hono/utils/mime";
4
- import { createReadStream, lstatSync } from "fs";
5
- var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
6
- var ENCODINGS = {
7
- br: ".br",
8
- zstd: ".zst",
9
- gzip: ".gz"
10
- };
11
- var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
12
- var createStreamBody = (stream) => {
13
- const body = new ReadableStream({
14
- start(controller) {
15
- stream.on("data", (chunk) => {
16
- controller.enqueue(chunk);
17
- });
18
- stream.on("end", () => {
19
- controller.close();
20
- });
21
- },
22
- cancel() {
23
- stream.destroy();
24
- }
25
- });
26
- return body;
27
- };
28
- var addCurrentDirPrefix = (path) => {
29
- return `./${path}`;
30
- };
31
- var getStats = (path) => {
32
- let stats;
33
- try {
34
- stats = lstatSync(path);
35
- } catch {
36
- }
37
- return stats;
38
- };
39
- var serveStatic = (options = { root: "" }) => {
40
- return async (c, next) => {
41
- if (c.finalized) {
42
- return next();
43
- }
44
- let filename;
45
- try {
46
- filename = options.path ?? decodeURIComponent(c.req.path);
47
- } catch {
48
- await options.onNotFound?.(c.req.path, c);
49
- return next();
50
- }
51
- let path = getFilePathWithoutDefaultDocument({
52
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
53
- root: options.root
54
- });
55
- if (path) {
56
- path = addCurrentDirPrefix(path);
57
- } else {
58
- return next();
59
- }
60
- let stats = getStats(path);
61
- if (stats && stats.isDirectory()) {
62
- path = getFilePath({
63
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
64
- root: options.root,
65
- defaultDocument: options.index ?? "index.html"
66
- });
67
- if (path) {
68
- path = addCurrentDirPrefix(path);
69
- } else {
70
- return next();
71
- }
72
- stats = getStats(path);
73
- }
74
- if (!stats) {
75
- await options.onNotFound?.(path, c);
76
- return next();
77
- }
78
- await options.onFound?.(path, c);
79
- const mimeType = getMimeType(path);
80
- c.header("Content-Type", mimeType || "application/octet-stream");
81
- if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
82
- const acceptEncodingSet = new Set(
83
- c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
84
- );
85
- for (const encoding of ENCODINGS_ORDERED_KEYS) {
86
- if (!acceptEncodingSet.has(encoding)) {
87
- continue;
88
- }
89
- const precompressedStats = getStats(path + ENCODINGS[encoding]);
90
- if (precompressedStats) {
91
- c.header("Content-Encoding", encoding);
92
- c.header("Vary", "Accept-Encoding", { append: true });
93
- stats = precompressedStats;
94
- path = path + ENCODINGS[encoding];
95
- break;
96
- }
97
- }
98
- }
99
- const size = stats.size;
100
- if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
101
- c.header("Content-Length", size.toString());
102
- c.status(200);
103
- return c.body(null);
104
- }
105
- const range = c.req.header("range") || "";
106
- if (!range) {
107
- c.header("Content-Length", size.toString());
108
- return c.body(createStreamBody(createReadStream(path)), 200);
109
- }
110
- c.header("Accept-Ranges", "bytes");
111
- c.header("Date", stats.birthtime.toUTCString());
112
- const parts = range.replace(/bytes=/, "").split("-", 2);
113
- const start = parts[0] ? parseInt(parts[0], 10) : 0;
114
- let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
115
- if (size < end - start + 1) {
116
- end = size - 1;
117
- }
118
- const chunksize = end - start + 1;
119
- const stream = createReadStream(path, { start, end });
120
- c.header("Content-Length", chunksize.toString());
121
- c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
122
- return c.body(createStreamBody(stream), 206);
123
- };
124
- };
125
-
126
- export {
127
- serveStatic
128
- };