@hono/node-server
Advanced tools
+21
-19
@@ -101,3 +101,2 @@ "use strict"; | ||
| } | ||
| await options.onFound?.(path, c); | ||
| const mimeType = (0, import_mime.getMimeType)(path); | ||
@@ -123,26 +122,29 @@ c.header("Content-Type", mimeType || "application/octet-stream"); | ||
| } | ||
| let result; | ||
| const size = stats.size; | ||
| const range = c.req.header("range") || ""; | ||
| if (c.req.method == "HEAD" || c.req.method == "OPTIONS") { | ||
| c.header("Content-Length", size.toString()); | ||
| c.status(200); | ||
| return c.body(null); | ||
| } | ||
| const range = c.req.header("range") || ""; | ||
| if (!range) { | ||
| result = c.body(null); | ||
| } else if (!range) { | ||
| c.header("Content-Length", size.toString()); | ||
| return c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200); | ||
| result = c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200); | ||
| } else { | ||
| c.header("Accept-Ranges", "bytes"); | ||
| c.header("Date", stats.birthtime.toUTCString()); | ||
| const parts = range.replace(/bytes=/, "").split("-", 2); | ||
| const start = parseInt(parts[0], 10) || 0; | ||
| let end = parseInt(parts[1], 10) || size - 1; | ||
| if (size < end - start + 1) { | ||
| end = size - 1; | ||
| } | ||
| const chunksize = end - start + 1; | ||
| const stream = (0, import_node_fs.createReadStream)(path, { start, end }); | ||
| c.header("Content-Length", chunksize.toString()); | ||
| c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`); | ||
| result = c.body(createStreamBody(stream), 206); | ||
| } | ||
| c.header("Accept-Ranges", "bytes"); | ||
| c.header("Date", stats.birthtime.toUTCString()); | ||
| const parts = range.replace(/bytes=/, "").split("-", 2); | ||
| const start = parseInt(parts[0], 10) || 0; | ||
| let end = parseInt(parts[1], 10) || size - 1; | ||
| if (size < end - start + 1) { | ||
| end = size - 1; | ||
| } | ||
| const chunksize = end - start + 1; | ||
| const stream = (0, import_node_fs.createReadStream)(path, { start, end }); | ||
| c.header("Content-Length", chunksize.toString()); | ||
| c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`); | ||
| return c.body(createStreamBody(stream), 206); | ||
| await options.onFound?.(path, c); | ||
| return result; | ||
| }; | ||
@@ -149,0 +151,0 @@ }; |
+21
-19
@@ -77,3 +77,2 @@ // src/serve-static.ts | ||
| } | ||
| await options.onFound?.(path, c); | ||
| const mimeType = getMimeType(path); | ||
@@ -99,26 +98,29 @@ c.header("Content-Type", mimeType || "application/octet-stream"); | ||
| } | ||
| let result; | ||
| const size = stats.size; | ||
| const range = c.req.header("range") || ""; | ||
| if (c.req.method == "HEAD" || c.req.method == "OPTIONS") { | ||
| c.header("Content-Length", size.toString()); | ||
| c.status(200); | ||
| return c.body(null); | ||
| } | ||
| const range = c.req.header("range") || ""; | ||
| if (!range) { | ||
| result = c.body(null); | ||
| } else if (!range) { | ||
| c.header("Content-Length", size.toString()); | ||
| return c.body(createStreamBody(createReadStream(path)), 200); | ||
| result = c.body(createStreamBody(createReadStream(path)), 200); | ||
| } else { | ||
| c.header("Accept-Ranges", "bytes"); | ||
| c.header("Date", stats.birthtime.toUTCString()); | ||
| const parts = range.replace(/bytes=/, "").split("-", 2); | ||
| const start = parseInt(parts[0], 10) || 0; | ||
| let end = parseInt(parts[1], 10) || size - 1; | ||
| if (size < end - start + 1) { | ||
| end = size - 1; | ||
| } | ||
| const chunksize = end - start + 1; | ||
| const stream = createReadStream(path, { start, end }); | ||
| c.header("Content-Length", chunksize.toString()); | ||
| c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`); | ||
| result = c.body(createStreamBody(stream), 206); | ||
| } | ||
| c.header("Accept-Ranges", "bytes"); | ||
| c.header("Date", stats.birthtime.toUTCString()); | ||
| const parts = range.replace(/bytes=/, "").split("-", 2); | ||
| const start = parseInt(parts[0], 10) || 0; | ||
| let end = parseInt(parts[1], 10) || size - 1; | ||
| if (size < end - start + 1) { | ||
| end = size - 1; | ||
| } | ||
| const chunksize = end - start + 1; | ||
| const stream = createReadStream(path, { start, end }); | ||
| c.header("Content-Length", chunksize.toString()); | ||
| c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`); | ||
| return c.body(createStreamBody(stream), 206); | ||
| await options.onFound?.(path, c); | ||
| return result; | ||
| }; | ||
@@ -125,0 +127,0 @@ }; |
+1
-1
| { | ||
| "name": "@hono/node-server", | ||
| "version": "1.19.5", | ||
| "version": "1.19.6", | ||
| "description": "Node.js Adapter for Hono", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
205182
0.08%6051
0.07%