CodeSampleX

샘플

@hono/node-server 2.0.12: serve

검증된 샘플 — npm @hono/node-server 2.0.12: serve. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: @hono/node-server exports serve function

sha256:8aec6b177101c5a225c6d071e1c67bdc32168d9e6db48be4d0d70d03cb49f66b

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-09-06

케이스

HOW
목표
verify @hono/node-server.serve in pkg:npm/%40hono/node-server@2.0.12
패키지
심벌
  • @hono/node-server.serve
환경
node 22.23.2
생성일
2026-09-06T13:30:40Z

컨트랙트

  1. @hono/node-server exports serve function
  2. serve starts an HTTP server and returns an http.Server instance
  3. serve invokes listeningListener with server AddressInfo including port and address
  4. serve handles HTTP GET requests and returns web-standard Response with status, headers, and body
  5. serve handles HTTP POST requests with JSON payload and request headers
  6. serve supports custom createServer option
  7. serve HTTP server closes cleanly

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.serve 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.serve
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.
csx.json
{"case":{"caseId":"case:sha256:f7e20cf24b2e8b0b2b8ce19bfea57660129661b74c0e09de7eec19a287eebb92","constraints":{"executionContext":"node"},"contract":["@hono/node-server exports serve function","serve starts an HTTP server and returns an http.Server instance","serve invokes listeningListener with server AddressInfo including port and address","serve handles HTTP GET requests and returns web-standard Response with status, headers, and body","serve handles HTTP POST requests with JSON payload and request headers","serve supports custom createServer option","serve HTTP server closes cleanly"],"goal":"verify @hono/node-server.serve 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.serve"]},"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","packageManagerVersion":"10.9.8","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.serve"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-hono-node-server-serve",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-node-server-serve",
      "version": "1.0.0",
      "license": "MIT-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"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-node-server-serve",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "description": "verify @hono/node-server.serve in pkg:npm/%40hono/node-server@2.0.12",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@hono/node-server": "2.0.12"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @hono/node-server.serve in pkg:npm/%40hono/node-server@2.0.12",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40hono/node-server@2.0.12"
  ],
  "symbols": [
    "@hono/node-server.serve"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import http from 'node:http';
import { serve } from '@hono/node-server';

// 1. @hono/node-server exports serve function
assert.strictEqual(typeof serve, 'function', '@hono/node-server must export serve function');

// 2. serve starts an HTTP server and returns an http.Server instance
// 3. serve invokes listeningListener with server AddressInfo including port and address
let listenerCalled = false;
let serverInfo = null;

const server = serve(
  {
    fetch: async (request) => {
      const url = new URL(request.url);

      if (url.pathname === '/hello' && request.method === 'GET') {
        return new Response('Hello from @hono/node-server.serve!', {
          status: 200,
          headers: {
            'content-type': 'text/plain; charset=utf-8',
            'x-custom-test': 'ok',
          },
        });
      }

      if (url.pathname === '/echo-json' && request.method === 'POST') {
        const body = await request.json();
        const customHeader = request.headers.get('x-client-header') || '';
        return new Response(JSON.stringify({ received: body, customHeader }), {
          status: 201,
          headers: { 'content-type': 'application/json' },
        });
      }

      return new Response('Not Found', { status: 404 });
    },
    port: 0,
    hostname: '127.0.0.1',
  },
  (info) => {
    listenerCalled = true;
    serverInfo = info;
  }
);

assert.ok(server instanceof http.Server, 'serve must return an http.Server instance');

await new Promise((resolve) => {
  if (server.listening && listenerCalled) {
    resolve();
  } else {
    server.once('listening', resolve);
  }
});

assert.strictEqual(listenerCalled, true, 'listeningListener callback should be invoked');
assert.ok(serverInfo, 'serverInfo should be provided to listeningListener');
assert.strictEqual(typeof serverInfo.port, 'number', 'port must be number');
assert.ok(serverInfo.port > 0, 'port must be > 0');
assert.strictEqual(serverInfo.address, '127.0.0.1', 'address must be 127.0.0.1');

const baseUrl = `http://127.0.0.1:${serverInfo.port}`;

// 4. serve handles HTTP GET requests and returns web-standard Response with status, headers, and body
const getRes = await fetch(`${baseUrl}/hello`);
assert.strictEqual(getRes.status, 200, 'GET status should be 200');
assert.strictEqual(getRes.headers.get('content-type'), 'text/plain; charset=utf-8');
assert.strictEqual(getRes.headers.get('x-custom-test'), 'ok');
const getText = await getRes.text();
assert.strictEqual(getText, 'Hello from @hono/node-server.serve!');

// 5. serve handles HTTP POST requests with JSON payload and request headers
const postPayload = { library: '@hono/node-server', version: '2.0.12' };
const postRes = await fetch(`${baseUrl}/echo-json`, {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'x-client-header': 'test-val-xyz',
  },
  body: JSON.stringify(postPayload),
});
assert.strictEqual(postRes.status, 201, 'POST status should be 201');
assert.strictEqual(postRes.headers.get('content-type'), 'application/json');
const postData = await postRes.json();
assert.deepStrictEqual(postData, {
  received: postPayload,
  customHeader: 'test-val-xyz',
});

// 6. serve supports custom createServer option
let customCreateServerCalled = false;
const customServer = serve({
  fetch: () => new Response('custom server response'),
  port: 0,
  hostname: '127.0.0.1',
  createServer: (...args) => {
    customCreateServerCalled = true;
    return http.createServer(...args);
  },
});

await new Promise((resolve) => {
  if (customServer.listening) resolve();
  else customServer.once('listening', resolve);
});

assert.strictEqual(customCreateServerCalled, true, 'custom createServer must be called');

const customAddr = customServer.address();
const customRes = await fetch(`http://127.0.0.1:${customAddr.port}/`);
assert.strictEqual(customRes.status, 200);
assert.strictEqual(await customRes.text(), 'custom server response');

// 7. serve HTTP server closes cleanly
await new Promise((resolve, reject) => {
  server.close((err) => (err ? reject(err) : resolve()));
});
assert.strictEqual(server.listening, false, 'server should not be listening after close');

await new Promise((resolve, reject) => {
  customServer.close((err) => (err ? reject(err) : resolve()));
});
assert.strictEqual(customServer.listening, false, 'customServer should not be listening after close');

console.log('All @hono/node-server.serve contract tests passed.');

오리진 시더

익명