Socket
Socket
Sign inDemoInstall

@hono/node-server

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/node-server - npm Package Compare versions

Comparing version 1.11.5 to 1.12.0

dist/conninfo.d.mts

46

dist/serve-static.js

@@ -45,2 +45,13 @@ "use strict";

};
var addCurrentDirPrefix = (path) => {
return `./${path}`;
};
var getStats = (path) => {
let stats;
try {
stats = (0, import_fs.lstatSync)(path);
} catch {
}
return stats;
};
var serveStatic = (options = { root: "" }) => {

@@ -52,12 +63,26 @@ return async (c, next) => {

const filename = options.path ?? decodeURIComponent(c.req.path);
let path = (0, import_filepath.getFilePath)({
let path = (0, import_filepath.getFilePathWithoutDefaultDocument)({
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
root: options.root,
defaultDocument: options.index ?? "index.html"
root: options.root
});
if (!path) {
if (path) {
path = addCurrentDirPrefix(path);
} else {
return next();
}
path = `./${path}`;
if (!(0, import_fs.existsSync)(path)) {
let stats = getStats(path);
if (stats && stats.isDirectory()) {
path = (0, import_filepath.getFilePath)({
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
root: options.root,
defaultDocument: options.index ?? "index.html"
});
if (path) {
path = addCurrentDirPrefix(path);
} else {
return next();
}
stats = getStats(path);
}
if (!stats) {
await options.onNotFound?.(path, c);

@@ -70,4 +95,3 @@ return next();

}
const stat = (0, import_fs.lstatSync)(path);
const size = stat.size;
const size = stats.size;
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {

@@ -84,6 +108,6 @@ c.header("Content-Length", size.toString());

c.header("Accept-Ranges", "bytes");
c.header("Date", stat.birthtime.toUTCString());
c.header("Date", stats.birthtime.toUTCString());
const parts = range.replace(/bytes=/, "").split("-", 2);
const start = parts[0] ? parseInt(parts[0], 10) : 0;
let end = parts[1] ? parseInt(parts[1], 10) : stat.size - 1;
let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
if (size < end - start + 1) {

@@ -95,3 +119,3 @@ end = size - 1;

c.header("Content-Length", chunksize.toString());
c.header("Content-Range", `bytes ${start}-${end}/${stat.size}`);
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
return c.body(createStreamBody(stream), 206);

@@ -98,0 +122,0 @@ };

{
"name": "@hono/node-server",
"version": "1.11.5",
"version": "1.12.0",
"description": "Node.js Adapter for Hono",

@@ -30,2 +30,7 @@ "main": "dist/index.js",

"import": "./dist/utils/*.mjs"
},
"./conninfo": {
"types": "./dist/conninfo.d.ts",
"require": "./dist/conninfo.js",
"import": "./dist/conninfo.mjs"
}

@@ -46,2 +51,5 @@ },

"./dist/utils/*.d.ts"
],
"conninfo": [
"./dist/conninfo.d.ts"
]

@@ -48,0 +56,0 @@ }

@@ -172,3 +172,3 @@ # Node.js Adapter for Hono

Typically, you would run your app from the project's root directory (`my-hono-project`),
Typically, you would run your app from the project's root directory (`my-hono-project`),
so you would need the following code to serve the `static` folder:

@@ -214,2 +214,15 @@

## ConnInfo Helper
You can use the [ConnInfo Helper](https://hono.dev/docs/helpers/conninfo) by importing `getConnInfo` from `@hono/node-server/conninfo`.
```ts
import { getConnInfo } from '@hono/node-server/conninfo'
app.get('/', (c) => {
const info = getConnInfo(c) // info is `ConnInfo`
return c.text(`Your remote address is ${info.remote.address}`)
})
```
## Accessing Node.js API

@@ -216,0 +229,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc