ft: single-origin deployment docs
a74a840c
1 file(s) · +120 −0
| 1 | + | # Single Origin Deployment |
|
| 2 | + | ||
| 3 | + | import { Button } from "vocs/components"; |
|
| 4 | + | ||
| 5 | + | Serve both your frontend and API from the same process, same port, and same origin—ideal for fullstack apps where simplicity matters. |
|
| 6 | + | ||
| 7 | + | This guide walks through deploying a bhvr project using a **single origin** approach. You’ll still get React + Vite on the frontend, Hono on the backend, and Bun running it all. |
|
| 8 | + | ||
| 9 | + | Perfect for: |
|
| 10 | + | ||
| 11 | + | - VPS deployments |
|
| 12 | + | - Raspberry Pis |
|
| 13 | + | - Home servers |
|
| 14 | + | - Projects where you want one URL to rule them all |
|
| 15 | + | ||
| 16 | + | ## What Is a Single Origin Deployment? |
|
| 17 | + | ||
| 18 | + | A single origin setup serves your client and your API from the same runtime and port: |
|
| 19 | + | ||
| 20 | + | - `bun` runs both your backend and static frontend |
|
| 21 | + | - `hono` handles both routes and static files |
|
| 22 | + | - Everything lives behind one port and one domain (like `https://yourapp.com`) |
|
| 23 | + | ||
| 24 | + | No CORS. No extra hops. No need for a separate web server unless you prefer one. |
|
| 25 | + | ||
| 26 | + | ## Folder Structure |
|
| 27 | + | ||
| 28 | + | Single origin works great with bhvr’s monorepo setup: |
|
| 29 | + | ||
| 30 | + | ``` |
|
| 31 | + | client/ → React + Vite frontend |
|
| 32 | + | server/ → Hono API backend |
|
| 33 | + | shared/ → Shared types and utilities |
|
| 34 | + | ``` |
|
| 35 | + | ||
| 36 | + | After building, you copy the output from `client` into the `server` so it can be served statically. |
|
| 37 | + | ||
| 38 | + | ## Why Use Single Origin? |
|
| 39 | + | ||
| 40 | + | - **No CORS headaches** |
|
| 41 | + | - **One tunnel or reverse proxy** to manage |
|
| 42 | + | - **Cleaner mental model** for small or embedded deployments |
|
| 43 | + | - Great fit for **low-resource devices** like Raspberry Pi |
|
| 44 | + | ||
| 45 | + | ## Build and Launch |
|
| 46 | + | ||
| 47 | + | That’s it. Your entire app is now served on port 3000 by a single Bun process. |
|
| 48 | + | ||
| 49 | + | ## Server Deployment Example |
|
| 50 | + | ||
| 51 | + | Whether you're deploying to a VPS, a Raspberry Pi, or a bare metal machine at home—if you can SSH into it and it runs a Unix-like OS, you're good to go. (This guide assumes a Linux/Unix server environment; Windows is not supported.) Here's a quick setup: |
|
| 52 | + | ||
| 53 | + | ### Install Bun |
|
| 54 | + | ||
| 55 | + | ```bash |
|
| 56 | + | curl -fsSL https://bun.sh/install | bash |
|
| 57 | + | ``` |
|
| 58 | + | ||
| 59 | + | ### Clone Your Project |
|
| 60 | + | ||
| 61 | + | ```bash |
|
| 62 | + | sudo mkdir -p /opt/app && sudo chown $USER:$USER /opt/app |
|
| 63 | + | cd /opt/app |
|
| 64 | + | ||
| 65 | + | git clone https://github.com/your/project.git app |
|
| 66 | + | cd app |
|
| 67 | + | ``` |
|
| 68 | + | ||
| 69 | + | ### Build and Copy |
|
| 70 | + | ||
| 71 | + | ```bash |
|
| 72 | + | bun install |
|
| 73 | + | bun run build |
|
| 74 | + | cp -r client/dist server/dist/client |
|
| 75 | + | ``` |
|
| 76 | + | ||
| 77 | + | ### systemd Service |
|
| 78 | + | ||
| 79 | + | ```ini |
|
| 80 | + | # /etc/systemd/system/app.service |
|
| 81 | + | [Unit] |
|
| 82 | + | Description=bhvr App – Single Origin |
|
| 83 | + | After=network-online.target |
|
| 84 | + | ||
| 85 | + | [Service] |
|
| 86 | + | User=youruser |
|
| 87 | + | WorkingDirectory=/opt/app |
|
| 88 | + | Environment=YOUR_ENV_VARS |
|
| 89 | + | ExecStart=/home/youruser/.bun/bin/bun run server/dist/server/src/index.js |
|
| 90 | + | Restart=always |
|
| 91 | + | RestartSec=5 |
|
| 92 | + | ||
| 93 | + | [Install] |
|
| 94 | + | WantedBy=multi-user.target |
|
| 95 | + | ``` |
|
| 96 | + | ||
| 97 | + | ```bash |
|
| 98 | + | sudo systemctl daemon-reload |
|
| 99 | + | sudo systemctl enable --now app |
|
| 100 | + | ``` |
|
| 101 | + | ||
| 102 | + | ### Expose It |
|
| 103 | + | ||
| 104 | + | You can expose the server using: |
|
| 105 | + | ||
| 106 | + | - [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/) |
|
| 107 | + | - [Caddy](https://caddyserver.com) |
|
| 108 | + | - [Tailscale Funnel](https://tailscale.com/funnel/) |
|
| 109 | + | ||
| 110 | + | Each of these lets you skip dealing with NAT, SSL, and port forwarding. |
|
| 111 | + | ||
| 112 | + | ## Summary |
|
| 113 | + | ||
| 114 | + | Single origin deployments are a great fit when you want everything bundled into one runtime and served from a single point of entry. |
|
| 115 | + | ||
| 116 | + | They’re fast, minimal, and don’t require any orchestration. |
|
| 117 | + | ||
| 118 | + | ## More Resources |
|
| 119 | + | ||
| 120 | + | <Button href='/getting-started'>Getting Started with bhvr</Button> |