Bun
For: a developer who wants sign-in in a Bun server with a Postgres database.
What it does: you run the Node example app with Bun, through Bun.serve. A script signs a person in with a magic link through the real server.
An agent can do these steps with the authtempo MCP server. See Set up an agent.
Before you start
Section titled “Before you start”- Do the Node tutorial first. This tutorial uses the same app,
examples/my-app. - Bun 1.4.3. The app pins it as a development tool, so
pnpm installputs it innode_modules/.bin.
The command authtempo init my-app --stack bun writes the Node app with bun src/main.ts as its start script. authtempo init tells how.
- Read
src/server-bun.ts. It serves the same handler withBun.serve, and sets the client IP from Bun’s own call.
import { CLIENT_IP_HEADER, type Serve } from "./app.ts";
export const serveBun: Serve = async (handler, options) => { const server = Bun.serve({ port: options.port, hostname: options.hostname, fetch(request, srv) { const headers = new Headers(request.headers); headers.delete(CLIENT_IP_HEADER); const ip = srv.requestIP(request)?.address; if (ip) headers.set(CLIENT_IP_HEADER, ip); return handler(new Request(request, { headers })); }, }); return { async close() { await server.stop(true); }, };};- Run the test of the app.
pnpm turbo run test --filter=my-app- Find the line
bun-e2e: PASSin the output. It comes after the line of the Node run. - At the root of the repo, start the server with Bun and the settings of your deploy.
DATABASE_URL="postgres://USER:PASSWORD@HOST:5432/DATABASE" AUTH_SECRET="<32 characters or more, from openssl rand -base64 32>" BASE_URL="https://api.example.com" HOST=0.0.0.0 PORT=3000 pnpm --filter my-app exec bun src/main.tssrc/main.ts picks Bun.serve when it runs under Bun, and Node’s http module when it runs under Node. The app code is the same under both.