샘플
@hono/node-server 2.1.11
검증된 샘플 — npm @hono/node-server 2.1.11. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: @hono/node-server exports serve, createAdaptorServer…
sha256:4df787b957b46d28a1f768a72886f4c822041fa39c1de4eebd40d271008e6a3b
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-11-28 |
케이스
HOW- 목표
- verify pkg:npm/%40hono/node-server@2.1.11
- 환경
- node 22.23.2
- 생성일
- 2026-11-28T04:03:01Z
컨트랙트
- @hono/node-server exports serve, createAdaptorServer, getRequestListener, RequestError, and upgradeWebSocket in CommonJS, and subpath exports @hono/node-server/conninfo and @hono/node-server/early-hints resolve in CommonJS
- RequestError extends Error, sets name to RequestError, and preserves the cause option
- serve binds an HTTP server on 127.0.0.1 with an ephemeral port, invokes listeningListener with AddressInfo, and dispatches GET and POST JSON requests
- createAdaptorServer returns an unstarted http.Server that passes incoming and outgoing HttpBindings compatible with getConnInfo
- getRequestListener forwards thrown RequestError instances to errorHandler and earlyHints sends 103 Early Hints Link headers for document navigation requests while skipping non-document requests
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/app.cjs
- test/contract.cjs
소스
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 pkg:npm/%40hono/node-server@2.1.11
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40hono/node-server@2.1.11
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- 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:502a9ec5182f07b13f56ecf08fc093aecca5a71279dda2d820348d32bb0e4411","constraints":{"executionContext":"node"},"contract":["@hono/node-server exports serve, createAdaptorServer, getRequestListener, RequestError, and upgradeWebSocket in CommonJS, and subpath exports @hono/node-server/conninfo and @hono/node-server/early-hints resolve in CommonJS","RequestError extends Error, sets name to RequestError, and preserves the cause option","serve binds an HTTP server on 127.0.0.1 with an ephemeral port, invokes listeningListener with AddressInfo, and dispatches GET and POST JSON requests","createAdaptorServer returns an unstarted http.Server that passes incoming and outgoing HttpBindings compatible with getConnInfo","getRequestListener forwards thrown RequestError instances to errorHandler and earlyHints sends 103 Early Hints Link headers for document navigation requests while skipping non-document requests"],"goal":"verify pkg:npm/%40hono/node-server@2.1.11","kind":"HOW","packages":["pkg:npm/%40hono/node-server@2.1.11"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40hono/node-server@2.1.11"],"schemaVersion":1,"subject":"pkg:npm/%40hono/node-server@2.1.11","verifierAdapter":"node-typescript@1"}
{
"name": "hono-node-server-verify",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "hono-node-server-verify",
"version": "1.0.0",
"dependencies": {
"@hono/node-server": "2.1.11"
}
},
"node_modules/@hono/node-server": {
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.11.tgz",
"integrity": "sha512-KzKz9vl4vvr1vgLHamj+g5uonbrj5NwAdO3yzOS6cd2HjALVeOgTgeZOyAzNxejbkfOOPIcvuf/Tg8l1pEFLog==",
"license": "MIT",
"engines": {
"node": ">=20"
},
"peerDependencies": {
"hono": "^4 || ^5.0.0-0"
}
},
"node_modules/hono": {
"version": "4.13.23",
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.23.tgz",
"integrity": "sha512-OS90dj7dcsftEEWCOef8jRbnHE5lbrOq0hNRqjSyPsOnaGZvvfof1KS05hQNb4kUOCfDq1mG3PmHoX37DMnHQg==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=16.9.0"
}
}
}
}
{
"name": "hono-node-server-verify",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"@hono/node-server": "2.1.11"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40hono/node-server@2.1.11",
"kind": "HOW",
"packages": [
"pkg:npm/%40hono/node-server@2.1.11"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const http = require('node:http');
const {
serve,
createAdaptorServer,
getRequestListener,
RequestError,
} = require('@hono/node-server');
const { getConnInfo } = require('@hono/node-server/conninfo');
const { earlyHints } = require('@hono/node-server/early-hints');
function createFetchHandler() {
const hintsMiddleware = earlyHints({
link: '</styles.css>; rel=preload; as=style',
});
return async (request, env) => {
const url = new URL(request.url);
if (request.method === 'GET' && url.pathname === '/health') {
return Response.json({ status: 'ok' }, { status: 200 });
}
if (request.method === 'POST' && url.pathname === '/echo') {
const payload = await request.json();
return Response.json(
{
received: payload,
customHeader: request.headers.get('x-trace-id'),
},
{ status: 201 }
);
}
if (request.method === 'GET' && url.pathname === '/conn') {
const conn = getConnInfo({ env });
return Response.json({
hasIncoming: Boolean(env && env.incoming),
hasOutgoing: Boolean(env && env.outgoing),
remote: conn.remote,
});
}
if (request.method === 'GET' && url.pathname === '/hints') {
let response;
const ctx = {
env,
req: {
header(name) {
return request.headers.get(name) ?? undefined;
},
},
};
await hintsMiddleware(ctx, async () => {
response = new Response('<html>ok</html>', {
status: 200,
headers: { 'content-type': 'text/html; charset=utf-8' },
});
});
return response;
}
if (request.method === 'GET' && url.pathname === '/fail') {
throw new RequestError('simulated bad request', {
cause: new Error('invalid query'),
});
}
return new Response('Not Found', { status: 404 });
};
}
function startWithServe(onListening) {
return serve(
{
fetch: createFetchHandler(),
hostname: '127.0.0.1',
port: 0,
},
onListening
);
}
function createServerWithoutListening() {
return createAdaptorServer({
fetch: createFetchHandler(),
hostname: '127.0.0.1',
});
}
function createListenerServer(onError) {
const listener = getRequestListener(createFetchHandler(), {
hostname: '127.0.0.1',
errorHandler(err) {
if (onError) onError(err);
return Response.json(
{
error: err instanceof Error ? err.name : 'UnknownError',
message: err instanceof Error ? err.message : String(err),
},
{ status: 400 }
);
},
});
return http.createServer(listener);
}
module.exports = {
createFetchHandler,
startWithServe,
createServerWithoutListening,
createListenerServer,
};
'use strict';
const assert = require('node:assert/strict');
const http = require('node:http');
const nodeServer = require('@hono/node-server');
const conninfo = require('@hono/node-server/conninfo');
const earlyHintsMod = require('@hono/node-server/early-hints');
const {
startWithServe,
createServerWithoutListening,
createListenerServer,
} = require('../src/app.cjs');
function httpRequest({ port, method = 'GET', path = '/', headers = {}, body = null }) {
return new Promise((resolve, reject) => {
const infoResponses = [];
const req = http.request(
{
hostname: '127.0.0.1',
port,
method,
path,
headers,
},
(res) => {
const chunks = [];
res.on('data', (chunk) => chunks.push(chunk));
res.on('end', () => {
resolve({
statusCode: res.statusCode,
headers: res.headers,
body: Buffer.concat(chunks).toString('utf8'),
infoResponses,
});
});
}
);
req.on('information', (info) => {
infoResponses.push({
statusCode: info.statusCode,
headers: info.headers,
});
});
req.on('error', reject);
if (body !== null) {
req.write(body);
}
req.end();
});
}
function closeServer(server) {
return new Promise((resolve, reject) => {
server.close((err) => (err ? reject(err) : resolve()));
});
}
async function testExportsAndRequestError() {
assert.equal(typeof nodeServer.serve, 'function');
assert.equal(typeof nodeServer.createAdaptorServer, 'function');
assert.equal(typeof nodeServer.getRequestListener, 'function');
assert.equal(typeof nodeServer.RequestError, 'function');
assert.equal(typeof nodeServer.upgradeWebSocket, 'function');
assert.equal(typeof conninfo.getConnInfo, 'function');
assert.equal(typeof earlyHintsMod.earlyHints, 'function');
const rootCause = new Error('underlying failure');
const reqErr = new nodeServer.RequestError('malformed input', { cause: rootCause });
assert.ok(reqErr instanceof Error);
assert.ok(reqErr instanceof nodeServer.RequestError);
assert.equal(reqErr.name, 'RequestError');
assert.equal(reqErr.message, 'malformed input');
assert.equal(reqErr.cause, rootCause);
}
async function testServeGetAndPost() {
let listeningInfo = null;
let server;
await new Promise((resolve) => {
server = startWithServe((info) => {
listeningInfo = info;
resolve();
});
});
try {
assert.ok(listeningInfo);
assert.equal(typeof listeningInfo.port, 'number');
assert.ok(listeningInfo.port > 0);
assert.equal(listeningInfo.address, '127.0.0.1');
const healthRes = await httpRequest({
port: listeningInfo.port,
method: 'GET',
path: '/health',
});
assert.equal(healthRes.statusCode, 200);
assert.deepEqual(JSON.parse(healthRes.body), { status: 'ok' });
const payload = JSON.stringify({ item: 'widget', count: 3 });
const echoRes = await httpRequest({
port: listeningInfo.port,
method: 'POST',
path: '/echo',
headers: {
'content-type': 'application/json',
'content-length': Buffer.byteLength(payload),
'x-trace-id': 'trace-42',
},
body: payload,
});
assert.equal(echoRes.statusCode, 201);
assert.deepEqual(JSON.parse(echoRes.body), {
received: { item: 'widget', count: 3 },
customHeader: 'trace-42',
});
} finally {
await closeServer(server);
}
}
async function testCreateAdaptorServerAndConnInfo() {
const server = createServerWithoutListening();
assert.ok(server instanceof http.Server);
assert.equal(server.listening, false);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
try {
assert.equal(server.listening, true);
const { port } = server.address();
const connRes = await httpRequest({
port,
method: 'GET',
path: '/conn',
});
assert.equal(connRes.statusCode, 200);
const data = JSON.parse(connRes.body);
assert.equal(data.hasIncoming, true);
assert.equal(data.hasOutgoing, true);
assert.equal(data.remote.address, '127.0.0.1');
assert.equal(data.remote.addressType, 'IPv4');
assert.equal(typeof data.remote.port, 'number');
assert.ok(data.remote.port > 0);
} finally {
await closeServer(server);
}
}
async function testGetRequestListenerAndEarlyHints() {
const capturedErrors = [];
const server = createListenerServer((err) => capturedErrors.push(err));
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
try {
const { port } = server.address();
const errRes = await httpRequest({
port,
method: 'GET',
path: '/fail',
});
assert.equal(errRes.statusCode, 400);
assert.equal(capturedErrors.length, 1);
assert.ok(capturedErrors[0] instanceof nodeServer.RequestError);
assert.equal(capturedErrors[0].cause.message, 'invalid query');
assert.deepEqual(JSON.parse(errRes.body), {
error: 'RequestError',
message: 'simulated bad request',
});
const navHintsRes = await httpRequest({
port,
method: 'GET',
path: '/hints',
headers: {
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Dest': 'document',
},
});
assert.equal(navHintsRes.statusCode, 200);
assert.equal(navHintsRes.body, '<html>ok</html>');
assert.equal(navHintsRes.infoResponses.length, 1);
assert.equal(navHintsRes.infoResponses[0].statusCode, 103);
assert.equal(
navHintsRes.infoResponses[0].headers.link,
'</styles.css>; rel=preload; as=style'
);
const apiHintsRes = await httpRequest({
port,
method: 'GET',
path: '/hints',
headers: {
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
},
});
assert.equal(apiHintsRes.statusCode, 200);
assert.equal(apiHintsRes.infoResponses.length, 0);
} finally {
await closeServer(server);
}
}
async function main() {
await testExportsAndRequestError();
await testServeGetAndPost();
await testCreateAdaptorServerAndConnInfo();
await testGetRequestListenerAndEarlyHints();
console.log('contract passed');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
오리진 시더
익명