CodeSampleX

Sample

@hono/node-server 2.1.1: createAdaptorServer

Verified sample for npm @hono/node-server 2.1.1: createAdaptorServer. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:1eea5e47576f9b7e675d5bea0c9807e9dbc69336d57827e6a6f0605c0211b214

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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-05

Case

HOW
Goal
verify @hono/node-server.createAdaptorServer in pkg:npm/%40hono/node-server@2.1.1
Packages
Symbols
  • @hono/node-server.createAdaptorServer
Environment
node 22.23.2
Created
2026-09-05T23:44:22Z

Contract

  1. @hono/node-server exports createAdaptorServer function
  2. createAdaptorServer creates an unstarted http.Server instance from fetch handler
  3. server created by createAdaptorServer can listen on a port and handle HTTP GET requests
  4. server created by createAdaptorServer dispatches HTTP POST requests with JSON payload
  5. createAdaptorServer passes HttpBindings with incoming and outgoing in fetch env argument
  6. createAdaptorServer supports custom createServer factory function in options
  7. createAdaptorServer server can be closed via server.close()

Files

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

Download the source artifact (tar.gz)

Source

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.createAdaptorServer in pkg:npm/%40hono/node-server@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40hono/node-server@2.1.1
Demonstrate these symbols/APIs:
  - @hono/node-server.createAdaptorServer

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:177bd2c2ae578cc6fb17b85b8a6551782df8210cbceede7006aced9c7334fb5f","contract":["@hono/node-server exports createAdaptorServer function","createAdaptorServer creates an unstarted http.Server instance from fetch handler","server created by createAdaptorServer can listen on a port and handle HTTP GET requests","server created by createAdaptorServer dispatches HTTP POST requests with JSON payload","createAdaptorServer passes HttpBindings with incoming and outgoing in fetch env argument","createAdaptorServer supports custom createServer factory function in options","createAdaptorServer server can be closed via server.close()"],"goal":"verify @hono/node-server.createAdaptorServer in pkg:npm/%40hono/node-server@2.1.1","kind":"HOW","packages":["pkg:npm/%40hono/node-server@2.1.1"],"schemaVersion":1,"symbols":["@hono/node-server.createAdaptorServer"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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.1.1"],"schemaVersion":1,"subject":"pkg:npm/%40hono/node-server@2.1.1","symbols":["@hono/node-server.createAdaptorServer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-hono-node-server-create-adaptor-server",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-node-server-create-adaptor-server",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@hono/node-server": "2.1.1"
      }
    },
    "node_modules/@hono/node-server": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.1.tgz",
      "integrity": "sha512-ELuehkj5VCBdgEw9zs+ivkKwyzzUCSQuE96YmiPvn1ECBoZCczbFXJLeEGMTYjphP6gydh4pHMqEYPVMYUVgQg==",
      "license": "MIT",
      "engines": {
        "node": ">=20"
      },
      "peerDependencies": {
        "hono": "^4"
      }
    },
    "node_modules/hono": {
      "version": "4.13.5",
      "resolved": "https://registry.npmjs.org/hono/-/hono-4.13.5.tgz",
      "integrity": "sha512-O6+/eCYRkzzzy0rPWwKLiGBR1nFuUPZynnwjxN1MBA62NNqbT0wQEzQyK2gSO5yDIDB336sXQleAhOHrzlYyKw==",
      "license": "MIT",
      "peer": true,
      "engines": {
        "node": ">=16.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-node-server-create-adaptor-server",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "@hono/node-server": "2.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @hono/node-server.createAdaptorServer in pkg:npm/%40hono/node-server@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40hono/node-server@2.1.1"
  ],
  "symbols": [
    "@hono/node-server.createAdaptorServer"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import http from 'node:http';
import { createAdaptorServer } from '@hono/node-server';

// Contract: @hono/node-server exports createAdaptorServer function
{
  assert.strictEqual(typeof createAdaptorServer, 'function');
}

// Contract: createAdaptorServer creates an unstarted http.Server instance from fetch handler
{
  const server = createAdaptorServer({
    fetch: () => new Response('ok'),
  });
  assert.ok(server instanceof http.Server);
  assert.strictEqual(server.listening, false);
}

// Contract: server created by createAdaptorServer can listen on a port and handle HTTP GET requests
// Contract: server created by createAdaptorServer dispatches HTTP POST requests with JSON payload
// Contract: createAdaptorServer passes HttpBindings with incoming and outgoing in fetch env argument
// Contract: createAdaptorServer server can be closed via server.close()
{
  let envReceived = null;
  const server = createAdaptorServer({
    fetch: async (req, env) => {
      envReceived = env;
      const url = new URL(req.url);
      if (url.pathname === '/hello' && req.method === 'GET') {
        return new Response(JSON.stringify({ message: 'world' }), {
          status: 200,
          headers: { 'content-type': 'application/json' },
        });
      }
      if (url.pathname === '/echo' && req.method === 'POST') {
        const body = await req.json();
        return new Response(JSON.stringify({ echoed: body }), {
          status: 201,
          headers: { 'content-type': 'application/json' },
        });
      }
      return new Response('Not Found', { status: 404 });
    },
  });

  await new Promise((resolve) => {
    server.listen(0, '127.0.0.1', resolve);
  });

  assert.strictEqual(server.listening, true);
  const address = server.address();
  assert.ok(address && typeof address === 'object');
  assert.strictEqual(typeof address.port, 'number');
  assert.strictEqual(address.address, '127.0.0.1');

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

  // GET request
  const getRes = await fetch(`${baseUrl}/hello`);
  assert.strictEqual(getRes.status, 200);
  assert.strictEqual(getRes.headers.get('content-type'), 'application/json');
  const getData = await getRes.json();
  assert.deepStrictEqual(getData, { message: 'world' });

  // Verify HttpBindings passed in fetch env
  assert.ok(envReceived !== null);
  assert.ok(envReceived.incoming instanceof http.IncomingMessage);
  assert.ok(envReceived.outgoing instanceof http.ServerResponse);

  // POST request
  const postRes = await fetch(`${baseUrl}/echo`, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ item: 123 }),
  });
  assert.strictEqual(postRes.status, 201);
  const postData = await postRes.json();
  assert.deepStrictEqual(postData, { echoed: { item: 123 } });

  // 404 Not Found
  const notFoundRes = await fetch(`${baseUrl}/unknown`);
  assert.strictEqual(notFoundRes.status, 404);

  // Contract: createAdaptorServer server can be closed via server.close()
  await new Promise((resolve, reject) => {
    server.close((err) => (err ? reject(err) : resolve()));
  });
  assert.strictEqual(server.listening, false);
}

// Contract: createAdaptorServer supports custom createServer factory function in options
{
  let customFactoryCalled = false;
  const server = createAdaptorServer({
    fetch: () => new Response('custom server'),
    createServer: (options, listener) => {
      customFactoryCalled = true;
      return http.createServer(options, listener);
    },
  });

  assert.strictEqual(customFactoryCalled, true);
  assert.ok(server instanceof http.Server);

  await new Promise((resolve) => {
    server.listen(0, '127.0.0.1', resolve);
  });

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

  await new Promise((resolve, reject) => {
    server.close((err) => (err ? reject(err) : resolve()));
  });
  assert.strictEqual(server.listening, false);
}

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

Origin Seeder

anonymous