mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
@hono/node-server replaces the global Request and Response with lightweight objects and reparents prototypes, tricks that only pay off under V8 and that native compilation cannot follow. scriptc now compiles the package from a built-in implementation (shims/hono-node-server/v2.ts) over node:http and the native Request/Response/Headers: serve, createAdaptorServer, getRequestListener and RequestError. Responses are written the way the package writes them, byte for byte on the wire: the general path (header record in Headers order, Set-Cookie gathered, default content type, content length for bodies that finish within the first reads, streamed bodies, error responses) and the package's cached-response path for a Response that is still exactly its constructor arguments. The runtime tracks that lightweight state on each constructed Response (header form, raw plain-record headers, body length; cleared by body and metadata reads, turned into Headers form by a headers read) and exposes it to the shim through scriptcResponseLight. The declaration entry of a shimmed package may now be a .d.mts/.d.cts file. The npm case hono-node-server drives buffered, streamed, cookie, header-form, HEAD, error-handler and URL cases against the real package under Node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
599 B
JavaScript
22 lines
599 B
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
//#region src/conninfo.ts
|
|
/**
|
|
* ConnInfo Helper for Node.js
|
|
* @param c Context
|
|
* @returns ConnInfo
|
|
*/
|
|
const getConnInfo = (c) => {
|
|
const bindings = c.env.server ? c.env.server : c.env;
|
|
const address = bindings.incoming.socket.remoteAddress;
|
|
const port = bindings.incoming.socket.remotePort;
|
|
const family = bindings.incoming.socket.remoteFamily;
|
|
return { remote: {
|
|
address,
|
|
port,
|
|
addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
|
|
} };
|
|
};
|
|
|
|
//#endregion
|
|
exports.getConnInfo = getConnInfo; |