Exemple
@hono/node-server 2.0.12: getRequestListener
Échantillon vérifié pour npm @hono/node-server 2.0.12: getRequestListener. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:274e15d92e351032fa350824012daed2b89d922cd95b53728dba556cbe823199
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-06 |
Cas
HOW- Objectif
- verify @hono/node-server.getRequestListener in pkg:npm/%40hono/node-server@2.0.12
- Paquets
- Symboles
-
- @hono/node-server.getRequestListener
- Environnement
- node 22.23.2
- Créé
- 2026-09-06T12:52:48Z
Contrat
- getRequestListener is exported as a function from @hono/node-server
- getRequestListener returns a Node.js HTTP request listener callback compatible with http.createServer
- getRequestListener passes Web Request and incoming/outgoing environment bindings to fetch callback
- getRequestListener writes Web Response status, headers, and text body to outgoing Node response
- getRequestListener handles asynchronous fetch callback parsing JSON request body and returning JSON response
- getRequestListener delegates caught fetch callback errors to custom errorHandler option
- getRequestListener dispatches HTTP requests through a Hono application fetch method
Fichiers
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify @hono/node-server.getRequestListener in pkg:npm/%40hono/node-server@2.0.12
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40hono/node-server@2.0.12
Demonstrate these symbols/APIs:
- @hono/node-server.getRequestListener
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:ab5d6e11b98d5d178ee32c3e3f625b8ba807391625355caa232cfb1ea2530dc7","constraints":{"executionContext":"node"},"contract":["getRequestListener is exported as a function from @hono/node-server","getRequestListener returns a Node.js HTTP request listener callback compatible with http.createServer","getRequestListener passes Web Request and incoming/outgoing environment bindings to fetch callback","getRequestListener writes Web Response status, headers, and text body to outgoing Node response","getRequestListener handles asynchronous fetch callback parsing JSON request body and returning JSON response","getRequestListener delegates caught fetch callback errors to custom errorHandler option","getRequestListener dispatches HTTP requests through a Hono application fetch method"],"goal":"verify @hono/node-server.getRequestListener in pkg:npm/%40hono/node-server@2.0.12","kind":"HOW","packages":["pkg:npm/%40hono/node-server@2.0.12"],"schemaVersion":1,"symbols":["@hono/node-server.getRequestListener"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40hono/node-server@2.0.12"],"schemaVersion":1,"subject":"pkg:npm/%40hono/node-server@2.0.12","symbols":["@hono/node-server.getRequestListener"],"verifierAdapter":"node-typescript@1"}
import { getRequestListener } from '@hono/node-server';
/**
* Creates a Node.js request listener from a fetch-compatible handler.
* @param {Function} fetchCallback - Request handler accepting Request and env bindings
* @param {object} [options] - Optional server adapter options
* @returns {Function} Node.js request listener function (incoming, outgoing) => Promise<void>
*/
export function createRequestListener(fetchCallback, options) {
return getRequestListener(fetchCallback, options);
}
export { getRequestListener };
{
"name": "sample-hono-node-server-request-listener",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-hono-node-server-request-listener",
"version": "1.0.0",
"dependencies": {
"@hono/node-server": "2.0.12"
}
},
"node_modules/@hono/node-server": {
"version": "2.0.12",
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.0.12.tgz",
"integrity": "sha512-eWpQYr67tqJLeaSUl0Q+TquuYfUdTibpOJlUMV2FfUP7+KqCC5TufnwnlXL6mobZBJbGAYRd7ZvEBDCbLInjhg==",
"license": "MIT",
"engines": {
"node": ">=20"
},
"peerDependencies": {
"hono": "^4"
}
},
"node_modules/hono": {
"version": "4.13.7",
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.7.tgz",
"integrity": "sha512-c8/gF9ac8Y78/agExVocyLevgR+JlpNB444Py0FSX8pJoPdYUfUzRcXtYEYGwt6l19qIlVZPN5Mfsw9jFShmQQ==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=16.9.0"
}
}
}
}
{
"name": "sample-hono-node-server-request-listener",
"version": "1.0.0",
"type": "module",
"private": true,
"dependencies": {
"@hono/node-server": "2.0.12"
}
}
{
"schemaVersion": 1,
"goal": "verify @hono/node-server.getRequestListener in pkg:npm/%40hono/node-server@2.0.12",
"kind": "HOW",
"packages": [
"pkg:npm/%40hono/node-server@2.0.12"
],
"symbols": [
"@hono/node-server.getRequestListener"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { getRequestListener, createRequestListener } from '../index.mjs';
import { Hono } from 'hono';
// 1. getRequestListener is exported as a function from @hono/node-server
assert.equal(typeof getRequestListener, 'function');
assert.equal(typeof createRequestListener, 'function');
// 2. getRequestListener returns a Node.js HTTP request listener callback compatible with http.createServer
{
const listener = getRequestListener(() => new Response('OK'));
assert.equal(typeof listener, 'function');
const server = createServer(listener);
assert.ok(server);
}
// 3. getRequestListener passes Web Request and incoming/outgoing environment bindings to fetch callback
{
let receivedMethod = null;
let receivedPath = null;
let receivedHeader = null;
let receivedEnv = null;
const listener = getRequestListener((req, env) => {
receivedMethod = req.method;
receivedPath = new URL(req.url).pathname;
receivedHeader = req.headers.get('x-custom-test');
receivedEnv = env;
return new Response('Handled');
});
const server = createServer(listener);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/test-path`, {
method: 'GET',
headers: { 'x-custom-test': 'hono-request-listener' },
});
assert.equal(res.status, 200);
assert.equal(await res.text(), 'Handled');
assert.equal(receivedMethod, 'GET');
assert.equal(receivedPath, '/test-path');
assert.equal(receivedHeader, 'hono-request-listener');
assert.ok(receivedEnv?.incoming);
assert.ok(receivedEnv?.outgoing);
} finally {
await new Promise((resolve) => server.close(resolve));
}
}
// 4. getRequestListener writes Web Response status, headers, and text body to outgoing Node response
{
const listener = getRequestListener(() => {
return new Response('custom response body', {
status: 202,
headers: {
'x-sample-header': 'custom-value',
},
});
});
const server = createServer(listener);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/status`);
assert.equal(res.status, 202);
assert.equal(res.headers.get('x-sample-header'), 'custom-value');
assert.equal(await res.text(), 'custom response body');
} finally {
await new Promise((resolve) => server.close(resolve));
}
}
// 5. getRequestListener handles asynchronous fetch callback parsing JSON request body and returning JSON response
{
const listener = getRequestListener(async (req) => {
const body = await req.json();
return new Response(JSON.stringify({ echoed: body, valid: true }), {
status: 201,
headers: { 'content-type': 'application/json' },
});
});
const server = createServer(listener);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/echo`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ name: 'listener-test' }),
});
assert.equal(res.status, 201);
assert.equal(res.headers.get('content-type'), 'application/json');
const data = await res.json();
assert.deepEqual(data, { echoed: { name: 'listener-test' }, valid: true });
} finally {
await new Promise((resolve) => server.close(resolve));
}
}
// 6. getRequestListener delegates caught fetch callback errors to custom errorHandler option
{
const listener = getRequestListener(
() => {
throw new Error('test-internal-error');
},
{
errorHandler: (err) => {
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
headers: { 'content-type': 'application/json' },
});
},
}
);
const server = createServer(listener);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/crash`);
assert.equal(res.status, 500);
const data = await res.json();
assert.deepEqual(data, { error: 'test-internal-error' });
} finally {
await new Promise((resolve) => server.close(resolve));
}
}
// 7. getRequestListener dispatches HTTP requests through a Hono application fetch method
{
const app = new Hono();
app.get('/hono-route', (c) => c.json({ framework: 'hono', status: 'ok' }));
const listener = getRequestListener(app.fetch);
const server = createServer(listener);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/hono-route`);
assert.equal(res.status, 200);
const json = await res.json();
assert.deepEqual(json, { framework: 'hono', status: 'ok' });
} finally {
await new Promise((resolve) => server.close(resolve));
}
}
console.log('All contract tests passed.');
Seeder d'origine
anonyme