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.2.0 to 1.2.1

dist/globals.d.mts

3

dist/globals.d.ts

@@ -1,1 +0,2 @@

export {};
export { }

@@ -24,4 +24,6 @@ "use strict";

));
var import_node_crypto = __toESM(require("node:crypto"));
const webFetch = global.fetch;
// src/globals.ts
var import_node_crypto = __toESM(require("crypto"));
var webFetch = global.fetch;
if (typeof global.crypto === "undefined") {

@@ -28,0 +30,0 @@ global.crypto = import_node_crypto.default;

@@ -1,2 +0,7 @@

export { serve, createAdaptorServer } from './server';
export { getRequestListener } from './listener';
export { createAdaptorServer, serve } from './server.js';
export { getRequestListener } from './listener.js';
import 'node:net';
import './types.js';
import 'node:http';
import 'node:https';
import 'node:http2';
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,12 +20,126 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
createAdaptorServer: () => import_server.createAdaptorServer,
getRequestListener: () => import_listener.getRequestListener,
serve: () => import_server.serve
createAdaptorServer: () => createAdaptorServer,
getRequestListener: () => getRequestListener,
serve: () => serve
});
module.exports = __toCommonJS(src_exports);
var import_server = require("./server");
var import_listener = require("./listener");
// src/server.ts
var import_node_http = require("http");
// src/listener.ts
var import_node_stream = require("stream");
var import_promises = require("stream/promises");
// src/globals.ts
var import_node_crypto = __toESM(require("crypto"));
var webFetch = global.fetch;
if (typeof global.crypto === "undefined") {
global.crypto = import_node_crypto.default;
}
global.fetch = (info, init) => {
init = {
// Disable compression handling so people can return the result of a fetch
// directly in the loader without messing with the Content-Encoding header.
compress: false,
...init
};
return webFetch(info, init);
};
// src/listener.ts
var regBuffer = /^no$/i;
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
var getRequestListener = (fetchCallback) => {
return async (incoming, outgoing) => {
const method = incoming.method || "GET";
const url = `http://${incoming.headers.host}${incoming.url}`;
const headerRecord = [];
const len = incoming.rawHeaders.length;
for (let i = 0; i < len; i += 2) {
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
}
const init = {
method,
headers: headerRecord
};
if (!(method === "GET" || method === "HEAD")) {
init.body = import_node_stream.Readable.toWeb(incoming);
init.duplex = "half";
}
let res;
try {
res = await fetchCallback(new Request(url.toString(), init));
} catch (e) {
res = new Response(null, { status: 500 });
if (e instanceof Error) {
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
res = new Response(null, { status: 504 });
}
}
}
const resHeaderRecord = {};
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
} else {
outgoing.setHeader(k, v);
}
}
outgoing.statusCode = res.status;
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
}
} catch (e) {
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
console.info("The user aborted a request.");
} else {
console.error(e);
outgoing.destroy(err);
}
}
} else {
outgoing.end();
}
};
};
// src/server.ts
var createAdaptorServer = (options) => {
const fetchCallback = options.fetch;
const requestListener = getRequestListener(fetchCallback);
const createServer = options.createServer || import_node_http.createServer;
const server = createServer(options.serverOptions || {}, requestListener);
return server;
};
var serve = (options, listeningListener) => {
const server = createAdaptorServer(options);
server.listen(options?.port ?? 3e3, options.hostname ?? "0.0.0.0", () => {
const serverInfo = server.address();
listeningListener && listeningListener(serverInfo);
});
return server;
};
// Annotate the CommonJS export names for ESM import in node:

@@ -30,0 +146,0 @@ 0 && (module.exports = {

@@ -1,5 +0,8 @@

import type { IncomingMessage, ServerResponse } from 'node:http';
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
import type { FetchCallback } from './types';
import './globals';
export declare const getRequestListener: (fetchCallback: FetchCallback) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>;
import { IncomingMessage, ServerResponse } from 'node:http';
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
import { FetchCallback } from './types.js';
import 'node:https';
declare const getRequestListener: (fetchCallback: FetchCallback) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>;
export { getRequestListener };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,3 +20,13 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/listener.ts
var listener_exports = {};

@@ -25,6 +37,25 @@ __export(listener_exports, {

module.exports = __toCommonJS(listener_exports);
var import_node_stream = require("node:stream");
var import_promises = require("node:stream/promises");
var import_globals = require("./globals");
const getRequestListener = (fetchCallback) => {
var import_node_stream = require("stream");
var import_promises = require("stream/promises");
// src/globals.ts
var import_node_crypto = __toESM(require("crypto"));
var webFetch = global.fetch;
if (typeof global.crypto === "undefined") {
global.crypto = import_node_crypto.default;
}
global.fetch = (info, init) => {
init = {
// Disable compression handling so people can return the result of a fetch
// directly in the loader without messing with the Content-Encoding header.
compress: false,
...init
};
return webFetch(info, init);
};
// src/listener.ts
var regBuffer = /^no$/i;
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
var getRequestListener = (fetchCallback) => {
return async (incoming, outgoing) => {

@@ -57,8 +88,5 @@ const method = incoming.method || "GET";

}
const contentType = res.headers.get("content-type") || "";
const buffering = res.headers.get("x-accel-buffering") || "";
const contentEncoding = res.headers.get("content-encoding");
const contentLength = res.headers.get("content-length");
const transferEncoding = res.headers.get("transfer-encoding");
const resHeaderRecord = {};
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {

@@ -73,3 +101,4 @@ outgoing.setHeader(k, res.headers.getSetCookie(k));

try {
if (contentEncoding || transferEncoding || contentLength || /^no$/i.test(buffering) || !/^(application\/json\b|text\/(?!event-stream\b))/i.test(contentType)) {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);

@@ -76,0 +105,0 @@ } else {

@@ -1,3 +0,4 @@

import type { MiddlewareHandler } from 'hono';
export declare type ServeStaticOptions = {
import { MiddlewareHandler } from 'hono';
declare type ServeStaticOptions = {
/**

@@ -11,2 +12,4 @@ * Root path, relative to current working directory. (absolute paths are not supported)

};
export declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
export { ServeStaticOptions, serveStatic };

@@ -19,2 +19,4 @@ "use strict";

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/serve-static.ts
var serve_static_exports = {};

@@ -26,5 +28,119 @@ __export(serve_static_exports, {

var import_fs = require("fs");
var import_filepath = require("hono/utils/filepath");
var import_mime = require("hono/utils/mime");
const createStreamBody = (stream) => {
// node_modules/hono/dist/utils/filepath.js
var getFilePath = (options) => {
let filename = options.filename;
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename))
return;
let root = options.root || "";
const defaultDocument = options.defaultDocument || "index.html";
if (filename.endsWith("/")) {
filename = filename.concat(defaultDocument);
} else if (!filename.match(/\.[a-zA-Z0-9]+$/)) {
filename = filename.concat("/" + defaultDocument);
}
filename = filename.replace(/^\.?[\/\\]/, "");
filename = filename.replace(/\\/, "/");
root = root.replace(/\/$/, "");
let path = root ? root + "/" + filename : filename;
path = path.replace(/^\.?\//, "");
return path;
};
// node_modules/hono/dist/utils/mime.js
var getMimeType = (filename) => {
const regexp = /\.([a-zA-Z0-9]+?)$/;
const match = filename.match(regexp);
if (!match)
return;
let mimeType = mimes[match[1]];
if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
mimeType += "; charset=utf-8";
}
return mimeType;
};
var mimes = {
aac: "audio/aac",
abw: "application/x-abiword",
arc: "application/x-freearc",
avi: "video/x-msvideo",
avif: "image/avif",
av1: "video/av1",
azw: "application/vnd.amazon.ebook",
bin: "application/octet-stream",
bmp: "image/bmp",
bz: "application/x-bzip",
bz2: "application/x-bzip2",
csh: "application/x-csh",
css: "text/css",
csv: "text/csv",
doc: "application/msword",
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
eot: "application/vnd.ms-fontobject",
epub: "application/epub+zip",
gif: "image/gif",
gz: "application/gzip",
htm: "text/html",
html: "text/html",
ico: "image/x-icon",
ics: "text/calendar",
jar: "application/java-archive",
jpeg: "image/jpeg",
jpg: "image/jpeg",
js: "text/javascript",
json: "application/json",
jsonld: "application/ld+json",
map: "application/json",
mid: "audio/x-midi",
midi: "audio/x-midi",
mjs: "text/javascript",
mp3: "audio/mpeg",
mp4: "video/mp4",
mpeg: "video/mpeg",
mpkg: "application/vnd.apple.installer+xml",
odp: "application/vnd.oasis.opendocument.presentation",
ods: "application/vnd.oasis.opendocument.spreadsheet",
odt: "application/vnd.oasis.opendocument.text",
oga: "audio/ogg",
ogv: "video/ogg",
ogx: "application/ogg",
opus: "audio/opus",
otf: "font/otf",
pdf: "application/pdf",
php: "application/php",
png: "image/png",
ppt: "application/vnd.ms-powerpoint",
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
rtf: "application/rtf",
sh: "application/x-sh",
svg: "image/svg+xml",
swf: "application/x-shockwave-flash",
tar: "application/x-tar",
tif: "image/tiff",
tiff: "image/tiff",
ts: "video/mp2t",
ttf: "font/ttf",
txt: "text/plain",
vsd: "application/vnd.visio",
wasm: "application/wasm",
webm: "video/webm",
weba: "audio/webm",
webp: "image/webp",
woff: "font/woff",
woff2: "font/woff2",
xhtml: "application/xhtml+xml",
xls: "application/vnd.ms-excel",
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
xml: "application/xml",
xul: "application/vnd.mozilla.xul+xml",
zip: "application/zip",
"3gp": "video/3gpp",
"3g2": "video/3gpp2",
"7z": "application/x-7z-compressed",
gltf: "model/gltf+json",
glb: "model/gltf-binary"
};
// src/serve-static.ts
var createStreamBody = (stream) => {
const body = new ReadableStream({

@@ -45,3 +161,3 @@ start(controller) {

};
const serveStatic = (options = { root: "" }) => {
var serveStatic = (options = { root: "" }) => {
return async (c, next) => {

@@ -52,3 +168,3 @@ if (c.finalized)

const filename = options.path ?? decodeURIComponent(url.pathname);
let path = (0, import_filepath.getFilePath)({
let path = getFilePath({
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,

@@ -64,3 +180,3 @@ root: options.root,

}
const mimeType = (0, import_mime.getMimeType)(path);
const mimeType = getMimeType(path);
if (mimeType) {

@@ -67,0 +183,0 @@ c.header("Content-Type", mimeType);

@@ -1,4 +0,10 @@

import type { AddressInfo } from 'node:net';
import type { Options, ServerType } from './types';
export declare const createAdaptorServer: (options: Options) => ServerType;
export declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
import { AddressInfo } from 'node:net';
import { Options, ServerType } from './types.js';
import 'node:http';
import 'node:https';
import 'node:http2';
declare const createAdaptorServer: (options: Options) => ServerType;
declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
export { createAdaptorServer, serve };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,3 +20,13 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/server.ts
var server_exports = {};

@@ -26,7 +38,94 @@ __export(server_exports, {

module.exports = __toCommonJS(server_exports);
var import_node_http = require("node:http");
var import_listener = require("./listener");
const createAdaptorServer = (options) => {
var import_node_http = require("http");
// src/listener.ts
var import_node_stream = require("stream");
var import_promises = require("stream/promises");
// src/globals.ts
var import_node_crypto = __toESM(require("crypto"));
var webFetch = global.fetch;
if (typeof global.crypto === "undefined") {
global.crypto = import_node_crypto.default;
}
global.fetch = (info, init) => {
init = {
// Disable compression handling so people can return the result of a fetch
// directly in the loader without messing with the Content-Encoding header.
compress: false,
...init
};
return webFetch(info, init);
};
// src/listener.ts
var regBuffer = /^no$/i;
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
var getRequestListener = (fetchCallback) => {
return async (incoming, outgoing) => {
const method = incoming.method || "GET";
const url = `http://${incoming.headers.host}${incoming.url}`;
const headerRecord = [];
const len = incoming.rawHeaders.length;
for (let i = 0; i < len; i += 2) {
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
}
const init = {
method,
headers: headerRecord
};
if (!(method === "GET" || method === "HEAD")) {
init.body = import_node_stream.Readable.toWeb(incoming);
init.duplex = "half";
}
let res;
try {
res = await fetchCallback(new Request(url.toString(), init));
} catch (e) {
res = new Response(null, { status: 500 });
if (e instanceof Error) {
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
res = new Response(null, { status: 504 });
}
}
}
const resHeaderRecord = {};
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
} else {
outgoing.setHeader(k, v);
}
}
outgoing.statusCode = res.status;
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
}
} catch (e) {
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
console.info("The user aborted a request.");
} else {
console.error(e);
outgoing.destroy(err);
}
}
} else {
outgoing.end();
}
};
};
// src/server.ts
var createAdaptorServer = (options) => {
const fetchCallback = options.fetch;
const requestListener = (0, import_listener.getRequestListener)(fetchCallback);
const requestListener = getRequestListener(fetchCallback);
const createServer = options.createServer || import_node_http.createServer;

@@ -36,3 +135,3 @@ const server = createServer(options.serverOptions || {}, requestListener);

};
const serve = (options, listeningListener) => {
var serve = (options, listeningListener) => {
const server = createAdaptorServer(options);

@@ -39,0 +138,0 @@ server.listen(options?.port ?? 3e3, options.hostname ?? "0.0.0.0", () => {

@@ -1,30 +0,28 @@

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { createServer, Server, ServerOptions as HttpServerOptions } from 'node:http';
import type { createServer as createHttpsServer, ServerOptions as HttpsServerOptions } from 'node:https';
import type { createSecureServer as createSecureHttp2Server, createServer as createHttp2Server, Http2Server, Http2SecureServer, SecureServerOptions as SecureHttp2ServerOptions, ServerOptions as Http2ServerOptions } from 'node:http2';
export declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
export declare type NextHandlerOption = {
import { Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
import { Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
declare type NextHandlerOption = {
fetch: FetchCallback;
};
export declare type ServerType = Server | Http2Server | Http2SecureServer;
declare type ServerType = Server | Http2Server | Http2SecureServer;
declare type createHttpOptions = {
serverOptions?: HttpServerOptions;
serverOptions?: ServerOptions$1;
createServer?: typeof createServer;
};
declare type createHttpsOptions = {
serverOptions?: HttpsServerOptions;
createServer?: typeof createHttpsServer;
serverOptions?: ServerOptions$2;
createServer?: typeof createServer$1;
};
declare type createHttp2Options = {
serverOptions?: Http2ServerOptions;
createServer?: typeof createHttp2Server;
serverOptions?: ServerOptions$3;
createServer?: typeof createServer$2;
};
declare type createSecureHttp2Options = {
serverOptions?: SecureHttp2ServerOptions;
createServer?: typeof createSecureHttp2Server;
serverOptions?: SecureServerOptions;
createServer?: typeof createSecureServer;
};
declare type ServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
export declare type Options = {
declare type Options = {
fetch: FetchCallback;

@@ -34,2 +32,3 @@ port?: number;

} & ServerOptions;
export {};
export { FetchCallback, NextHandlerOption, Options, ServerType };

@@ -1,4 +0,7 @@

/// <reference types="node" />
/// <reference types="node" />
import type { Hono } from 'hono';
export declare const handle: (app: Hono<any, any, any>) => (incoming: import("http").IncomingMessage | import("http2").Http2ServerRequest, outgoing: import("http").ServerResponse<import("http").IncomingMessage> | import("http2").Http2ServerResponse) => Promise<void>;
import * as http2 from 'http2';
import * as http from 'http';
import { Hono } from 'hono';
declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse<http.IncomingMessage> | http2.Http2ServerResponse) => Promise<void>;
export { handle };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,3 +20,13 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/vercel.ts
var vercel_exports = {};

@@ -25,6 +37,93 @@ __export(vercel_exports, {

module.exports = __toCommonJS(vercel_exports);
var import_listener = require("./listener");
const handle = (app) => {
return (0, import_listener.getRequestListener)(app.fetch);
// src/listener.ts
var import_node_stream = require("stream");
var import_promises = require("stream/promises");
// src/globals.ts
var import_node_crypto = __toESM(require("crypto"));
var webFetch = global.fetch;
if (typeof global.crypto === "undefined") {
global.crypto = import_node_crypto.default;
}
global.fetch = (info, init) => {
init = {
// Disable compression handling so people can return the result of a fetch
// directly in the loader without messing with the Content-Encoding header.
compress: false,
...init
};
return webFetch(info, init);
};
// src/listener.ts
var regBuffer = /^no$/i;
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
var getRequestListener = (fetchCallback) => {
return async (incoming, outgoing) => {
const method = incoming.method || "GET";
const url = `http://${incoming.headers.host}${incoming.url}`;
const headerRecord = [];
const len = incoming.rawHeaders.length;
for (let i = 0; i < len; i += 2) {
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
}
const init = {
method,
headers: headerRecord
};
if (!(method === "GET" || method === "HEAD")) {
init.body = import_node_stream.Readable.toWeb(incoming);
init.duplex = "half";
}
let res;
try {
res = await fetchCallback(new Request(url.toString(), init));
} catch (e) {
res = new Response(null, { status: 500 });
if (e instanceof Error) {
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
res = new Response(null, { status: 504 });
}
}
}
const resHeaderRecord = {};
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
} else {
outgoing.setHeader(k, v);
}
}
outgoing.statusCode = res.status;
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
}
} catch (e) {
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
console.info("The user aborted a request.");
} else {
console.error(e);
outgoing.destroy(err);
}
}
} else {
outgoing.end();
}
};
};
// src/vercel.ts
var handle = (app) => {
return getRequestListener(app.fetch);
};
// Annotate the CommonJS export names for ESM import in node:

@@ -31,0 +130,0 @@ 0 && (module.exports = {

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

@@ -42,3 +42,4 @@ "main": "dist/index.js",

"test": "jest",
"build": "rimraf dist && tsx ./build.ts",
"build": "tsup",
"watch": "tsup --watch",
"postbuild": "publint",

@@ -60,21 +61,18 @@ "prerelease": "yarn build && yarn test",

"engines": {
"node": ">=18.0.0"
"node": ">=18.14.1"
},
"dependencies": {},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.3",
"@types/node": "^18.7.16",
"@types/supertest": "^2.0.12",
"esbuild": "^0.18.13",
"hono": "^3.3.4",
"hono": "^3.9.2",
"jest": "^29.6.1",
"np": "^7.7.0",
"publint": "^0.1.16",
"rimraf": "^3.0.2",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"tsx": "^3.12.7",
"tsup": "^7.2.0",
"typescript": "^4.8.3"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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