| 1 | # Orbiter |
| 2 | |
| 3 | import { Button } from 'vocs/components' |
| 4 | |
| 5 | <img src="https://docs.orbiter.host/light_logo.svg" alt="orbiter" className="mx-auto" /> |
| 6 | |
| 7 | Much like the [inspiration](/why-bhvr) behind bhvr, [Orbiter](https://orbiter.host) is a site hosting platform built on the principles that the web should be open and without walled gardens. It features many of the things every dev wants: |
| 8 | |
| 9 | - Simple CLI for local builds and deployments |
| 10 | - Custom Domains |
| 11 | - Analytics |
| 12 | - Version Control for easy rollbacks |
| 13 | - GitHub actions for automated deployments |
| 14 | - Serverless Functions |
| 15 | |
| 16 | In this guide we'll show you how to deploy your [`server`](/packages/server) to Orbiter Functions. |
| 17 | |
| 18 | ## Server Deployment |
| 19 | |
| 20 | ::::note |
| 21 | Orbiter Functions are only available on paid plans. [Upgrade today!](https://app.orbiter.host/billing) |
| 22 | :::: |
| 23 | |
| 24 | ### Quickstart |
| 25 | |
| 26 | If you haven't already created your bhvr app you can quickly create one using the Orbiter CLI |
| 27 | |
| 28 | ::::steps |
| 29 | |
| 30 | #### Setup Orbiter Account |
| 31 | |
| 32 | Visit [app.orbiter.host](https://app.orbiter.host) to create an account and make an API key on the [App Dashboard](https://app.orbiter.host) or on the [Keys Page](https://app.orbiter.host/api-keys). |
| 33 | |
| 34 | #### Install the Orbiter CLI and Authorize |
| 35 | |
| 36 | ```bash [terminal] |
| 37 | bun add -g orbiter-cli@latest |
| 38 | ``` |
| 39 | |
| 40 | ```bash [terminal] |
| 41 | orbiter auth |
| 42 | ``` |
| 43 | |
| 44 | #### Create a New bhvr Project |
| 45 | |
| 46 | Orbiter includes a special version of bhvr that has everything you need to have a fullstack app |
| 47 | |
| 48 | ```bash [terminal] |
| 49 | orbiter new --template bhvr |
| 50 | ``` |
| 51 | |
| 52 | This will automatically install, build, and deploy the client and server packages of your bhvr project! |
| 53 | |
| 54 | #### Deploy |
| 55 | |
| 56 | Whenever you need to upload, simply run any of the `deploy` commands |
| 57 | |
| 58 | ```bash [terminal] |
| 59 | bun run deploy:client |
| 60 | bun run deploy:server |
| 61 | bun run deploy # Deploys both client and server |
| 62 | ``` |
| 63 | |
| 64 | :::: |
| 65 | |
| 66 | ### Manual Setup |
| 67 | |
| 68 | Follow this guide if you already have an existing bhvr project you want to deploy to Orbiter |
| 69 | |
| 70 | ::::steps |
| 71 | |
| 72 | #### Setup Orbiter Account |
| 73 | |
| 74 | Visit [app.orbiter.host](https://app.orbiter.host) to create an account and make an API key on the [App Dashboard](https://app.orbiter.host) or on the [Keys Page](https://app.orbiter.host/api-keys). |
| 75 | |
| 76 | #### Install the Orbiter CLI and Authorize |
| 77 | |
| 78 | ```bash [terminal] |
| 79 | bun add -g orbiter-cli@latest |
| 80 | ``` |
| 81 | |
| 82 | ```bash [terminal] |
| 83 | orbiter auth |
| 84 | ``` |
| 85 | |
| 86 | #### Update Export Format |
| 87 | |
| 88 | Update the code inside `server/src/index.ts` to use the export format required by Orbiter Functions: |
| 89 | |
| 90 | ```typescript [server/src/index.ts] |
| 91 | import { Hono } from 'hono' |
| 92 | import { cors } from 'hono/cors' |
| 93 | import type { ApiResponse } from 'shared/dist' |
| 94 | |
| 95 | const app = new Hono() |
| 96 | |
| 97 | app.use(cors()) |
| 98 | |
| 99 | app.get('/', (c) => { |
| 100 | return c.text('Hello Hono!') |
| 101 | }) |
| 102 | |
| 103 | app.get('/hello', async (c) => { |
| 104 | |
| 105 | const data: ApiResponse = { |
| 106 | message: "Hello BHVR!", |
| 107 | success: true |
| 108 | } |
| 109 | |
| 110 | return c.json(data, { status: 200 }) |
| 111 | }) |
| 112 | |
| 113 | export default app; // [!code --] |
| 114 | export default { // [!code ++] |
| 115 | async fetch(request: Request, env: any, ctx: any) { // [!code ++] |
| 116 | return app.fetch(request, env, ctx) // [!code ++] |
| 117 | } // [!code ++] |
| 118 | }; // [!code ++] |
| 119 | ``` |
| 120 | |
| 121 | #### Deploy Server |
| 122 | |
| 123 | Move into the `server` package and run the deploy command with the server flag: |
| 124 | |
| 125 | ```bash [terminal] |
| 126 | cd server |
| 127 | |
| 128 | orbiter deploy --server |
| 129 | ``` |
| 130 | |
| 131 | This will: |
| 132 | - Ask which site you want to link the server to (you must already have a client site deployed on Orbiter) |
| 133 | - Ask for the entry path for your server code (typically `src/index.ts`) |
| 134 | - Ask for your desired build folder (typically `dist`) |
| 135 | - Save your preferences to an `orbiter.json` file |
| 136 | - Build and bundle your server code |
| 137 | - Deploy it to Orbiter |
| 138 | |
| 139 | If successful, you'll see a returned URL where you can access your API! |
| 140 | |
| 141 | :::: |
| 142 | |
| 143 | ## Environment Variables |
| 144 | |
| 145 | If you need to use environment variables in your server, create a `.env` file with your values, then include the `--env` flag when deploying: |
| 146 | |
| 147 | ```bash [terminal] |
| 148 | orbiter deploy --server --env |
| 149 | ``` |
| 150 | |
| 151 | This will automatically scan your `.env` file and include the variables in the deployment. Orbiter will never be able to see your variables, so make sure they are correct! |
| 152 | |
| 153 | ::::tip |
| 154 | You can also edit environment variables inside the [Orbiter App](https://app.orbiter.host) |
| 155 | :::: |
| 156 | |
| 157 | ## GitHub Actions |
| 158 | |
| 159 | You can set up GitHub Actions to automatically deploy your server whenever you push to your main branch. |
| 160 | |
| 161 | Create a `.github/workflows/deploy.yaml` file in the root of your project: |
| 162 | |
| 163 | ```bash [terminal] |
| 164 | mkdir -p .github/workflows && touch .github/workflows/deploy.yaml |
| 165 | ``` |
| 166 | |
| 167 | Paste the following code into the `deploy.yaml` file: |
| 168 | |
| 169 | ```yaml |
| 170 | name: "Deploy to Orbiter" |
| 171 | |
| 172 | on: |
| 173 | push: |
| 174 | branches: [main] |
| 175 | |
| 176 | jobs: |
| 177 | deploy: |
| 178 | runs-on: ubuntu-latest |
| 179 | steps: |
| 180 | - name: Checkout code |
| 181 | uses: actions/checkout@v4 |
| 182 | |
| 183 | - name: Setup Bun |
| 184 | uses: oven-sh/setup-bun@v1 |
| 185 | with: |
| 186 | bun-version: latest |
| 187 | |
| 188 | - name: Install dependencies |
| 189 | run: bun install |
| 190 | |
| 191 | - name: Deploy to Orbiter |
| 192 | env: |
| 193 | ORBITER_API_KEY: ${{ secrets.ORBITER_API_KEY }} |
| 194 | run: bunx orbiter-cli@latest deploy-server --siteId YOUR_SITE_ID --entryFile src/index.ts --buildDir dist |
| 195 | ``` |
| 196 | |
| 197 | Replace `YOUR_SITE_ID` with your actual site ID, which can be found by clicking the "ℹ" icon on the [Orbiter dashboard](https://app.orbiter.host). |
| 198 | |
| 199 | You'll need to add your Orbiter API key as a repository secret. Navigate to GitHub project Settings > Secrets and Variables > Actions. Click `New repository secret`, then use `ORBITER_API_KEY` as the name, and paste your API key into the box below. |
| 200 | |
| 201 | ## Further Reference |
| 202 | |
| 203 | For more information about how to use Orbiter Functions, visit the official docs: |
| 204 | |
| 205 | <Button href="https://docs.orbiter.host/functions">Orbiter Functions Docs</Button> |