@perryts/hono-server
v0.1.0
Published
Hono server adapter for Perry-native compile — serve({ fetch, port }) over Perry's bundled Fastify
Maintainers
Readme
@perryts/hono-server
Hono's standard serve({ fetch, port }) adapter contract for Perry-native
compile, wrapping Perry's bundled Fastify.
Hono is runtime-agnostic — the same (request: Request) => Response handler
runs on Workers, Bun, Deno, Node, and now Perry. This package is the Perry
counterpart to @hono/node-server / @hono/bun: one versioned, well-tested
place that absorbs the Perry-specific quirks instead of every app vendoring
its own shim.
Usage
import { Hono } from 'hono'
import { serve } from '@perryts/hono-server'
const app = new Hono()
app.get('/', (c) => c.json({ ok: true }))
serve({ fetch: app.fetch, port: 3000 }, (info) => {
console.log(`listening on :${info.port}`)
})Compile and run as a native binary:
perry compile src/server.ts -o server && ./serverAPI
function serve(opts: ServeOptions, listener?: (info: ServeInfo) => void): void
interface ServeOptions {
fetch: (request: Request) => Response | Promise<Response> // e.g. app.fetch
port: number
hostname?: string // default '0.0.0.0'
}
interface ServeInfo {
port: number
address: string
family: 'IPv4' | 'IPv6'
}Requirements
- Perry ≥ 0.5.1027 — relies on
Request.headersbeing a realHeadersobject (#1649); inside Hono,c.req.headers.get(...)runs on the adapter's hot path.
How it works
A single Fastify catch-all route (app.all('/*', …)) translates each Fastify
request into a Web Request, awaits opts.fetch, then copies the resulting
Response's status / headers / body onto the Fastify reply. Bodies are
buffered via res.text(); once response-body streaming is wired end-to-end
(#1650) the adapter can stream
res.body straight through.
Tracked at #1654.
