Vercel Deployment#
BunTok supports zero-config deployment on Vercel with Bun runtime. Select "Yes" when prompted during buntok init to set up the clean entry point pattern.
How It Works#
BunTok uses a single server.ts entry point for all modes — local development and Vercel. The app.listen() method auto-detects the runtime: it calls Bun.serve() locally, and works seamlessly on Vercel serverless.
server.ts — universal entry point#
typescript
import { app } from "./src/index";
import { env } from "./src/env";
app.listen(env.PORT);Why `app.listen()` Works Everywhere#
- Local dev —
app.listen()callsBun.serve()and binds to a port - Vercel —
app.listen()detects the serverless environment and delegates toapp.fetch()automatically - No separate entry points needed — one
server.tsworks for both
app.fetch() vs app.listen()#
| Method | Use Case | Binds Port |
|---|---|---|
| app.listen(port) | Local development | Yes |
| app.fetch(request) | Vercel/serverless | No |
| app.request(input, init?) | Testing | No |
vercel.json#
Generated by buntok init when Vercel is selected:
json
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"framework": "bun",
"bunVersion": "1.4.x"
}framework: "bun"— tells Vercel to use Bun runtime (required for GitHub-triggered deploys).bunVersion: "1.4.x"— pins the Bun runtime version.
Deploy#
bash
# Install Vercel CLI
npm i -g vercel
# Deploy (preview)
vercel
# Production deploy
vercel --prodLocal Development#
bash
bun run dev # runs: bun --watch server.tsThe dev script runs server.ts which calls app.listen() — this is separate from the Vercel entry point.
Project Structure#
typescript
my-app/
├── src/
│ ├── index.ts # export const app = new App()
│ ├── env.ts # App.validateEnv({ PORT, ... })
│ ├── controllers/
│ ├── services/
│ └── repositories/
├── server.ts # app.listen(env.PORT) — universal entry point
├── vercel.json # Vercel config (framework: "bun")
├── package.json
└── ...Notes#
- WebSocket routes may need additional Vercel configuration
- For monorepos, set the Root Directory in Vercel dashboard to your project subfolder
Info
app.listen() is the universal entry point — it works for both local development and Vercel serverless. No special configuration needed.