Backends
Hono, Express, Koa and any fetch handler, with no front end.
A backend with no front end needs no bundler of its own: build() from
@zeroko-io/core bundles its entry, every dependency in it, and deploys it.
npm install -D @zeroko-io/core// build.js, run by "build": "node build.js"
import { build } from "@zeroko-io/core"
await build({ entry: "src/index.ts" })Its options are the SDK's, and assets, a directory of files
to serve as they are.
Hono
A Hono app is a service as it is: its default export has fetch. The
bindings are in c.env.
import type { Database } from "@zeroko-io/core"
import { Hono } from "hono"
const app = new Hono<{ Bindings: { DB: Database } }>()
app.post("/notes", async (c) => {
const { text } = await c.req.json()
const { lastRowId } = await c.env.DB.run("INSERT INTO notes (text) VALUES (?)", text)
return c.json({ id: lastRowId }, 201)
})
export default appAny other module whose default export has fetch(request, env, ctx) works
the same way.
Express and Koa
Node's HTTP servers run through workerd's Node compatibility: node()
makes a service of an app.
import { node } from "@zeroko-io/core/node"
import express from "express"
const app = express()
app.use(express.json())
app.get("/", (req, res) => res.json({ hello: "world" }))
export default node(app)For Koa, node(app.callback()); a node:http server works too. An app
that gets ready on its own (it waits for something before serving) goes as
a function, called on the first request: a module can't wait for
anything at its top level.
export default node(async () => {
const app = await makeApp()
return app
})These apps don't get the bindings as arguments: read them from
cloudflare:workers, where workerd keeps them.
import { env } from "cloudflare:workers"
app.get("/notes", async (req, res) => res.json(await env.DB.query("SELECT * FROM notes")))What doesn't run
Fastify compiles its schemas into code at runtime, which a worker can't: it doesn't run on Zeroko, as on any workers runtime. Hono, Express and Koa do.