Bun Fullstack Dev Server
A MentraOS mini app is a single Bun process that does three things at once:- Connects to the MentraOS cloud via WebSocket (handled by
MiniAppServer) - Serves API routes via Hono (for your webview to call)
- Serves the webview frontend (HTML, JS, CSS) via Bun’s fullstack dev server
How it works
MiniAppServer extends Hono, so you add routes directly onto it. When you call Bun.serve(), you pass HTML imports as static routes and your app’s fetch method as the fallback handler. Bun automatically bundles your HTML files, resolving script tags, CSS imports, and module dependencies.
- HTML files imported with
import page from "./index.html"become bundled routes <script type="module" src="./frontend.tsx">is transpiled and bundled automatically- In development, HMR (hot module replacement) is built in
- All other requests fall through to Hono, which handles
/api/*routes and the/webhookendpoint
Example setup
This is based on how the stream-test app works. Every MentraOS mini app follows the same pattern:What each part does
| Part | Purpose |
|---|---|
import indexHtml from "./frontend/index.html" | Bun bundles the HTML and all its imports at build time |
routes: { "/webview": indexHtml } | Serves the bundled frontend at these paths |
fetch(request) { return app.fetch(request) } | Everything else (API routes, webhook) goes through Hono |
idleTimeout: 255 | Keeps SSE connections alive for real-time updates |
development: { hmr: true } | Enables hot module replacement during development |
The HTML entry point
Your HTML file references a TSX script and stylesheet. Bun handles the rest:src="./frontend.tsx" and automatically transpiles and bundles it. No separate build step needed.
Tailwind CSS
Tailwind v4 works out of the box with abunfig.toml in your project root:
href:
@apply, @layer, etc.) and serves compiled CSS. No PostCSS config, no CLI watcher.
Mounting sub-routers
For larger apps, you can split API routes into separate Hono routers and mount them:Why this matters
- One process, one port, one URL. No separate frontend dev server, no proxy config.
- No CORS issues. The webview and API share the same origin.
- Single deployment target. The cloud hits
/webhookon your URL. The phone loads/webviewon the same URL. - HMR in development. Edit your frontend code and see changes instantly without a page reload.
- No separate build step. Bun bundles HTML imports, transpiles TSX, and processes CSS on the fly.
Further reading
- Bun Fullstack Dev Server docs - The full reference for HTML imports,
Bun.serve()routes, and HMR - Hono documentation - The web framework that
MiniAppServerextends - Webview Authentication - How to authenticate users in your webview

