feat: Added Railway deployment docs 0880d6ec
Steve · 2025-06-08 17:09 2 file(s) · +80 −0
docs/pages/deployment/server/railway.mdx (added) +76 −0
1 +
# Railway
2 +
3 +
For a simple Bun server deployment you can use Railway by changing just a few lines of code.
4 +
5 +
::::steps
6 +
7 +
### Update `app` export
8 +
9 +
Update the code inside `server/src/index.ts` and use the export below which gives Railway access to the host and port.
10 +
11 +
```typescript [srver/src/index.ts]
12 +
import { Hono } from 'hono'
13 +
import { cors } from 'hono/cors'
14 +
import type { ApiResponse } from 'shared/dist'
15 +
16 +
const app = new Hono()
17 +
18 +
app.use(cors())
19 +
20 +
app.get('/', (c) => {
21 +
  return c.text('Hello Hono!')
22 +
})
23 +
24 +
app.get('/hello', async (c) => {
25 +
26 +
  const data: ApiResponse = {
27 +
    message: "Hello BHVR!",
28 +
    success: true
29 +
  }
30 +
31 +
  return c.json(data, { status: 200 })
32 +
})
33 +
34 +
export default app; // [!code --]
35 +
export default { // [!code ++]
36 +
  port: Number(process.env.PORT) || 3000, // [!code ++]
37 +
  hostname: '0.0.0.0', // [!code ++]
38 +
  fetch: app.fetch, // [!code ++]
39 +
}; // [!code ++]
40 +
```
41 +
42 +
### Add start command
43 +
44 +
Inside the root `package.json` add a new `start` command that will be used by Railway for deployment
45 +
46 +
```json [package.json]
47 +
// Rest of package.json
48 +
  "scripts": {
49 +
    "dev:client": "cd client && bun run dev",
50 +
    "dev:server": "cd server && bun run dev",
51 +
    "dev:shared": "cd shared && bun run dev",
52 +
    "dev": "concurrently \"bun run dev:shared\" \"bun run dev:server\" \"bun run dev:client\"",
53 +
    "build:client": "cd client && bun run build",
54 +
    "build:shared": "cd shared && bun run build",
55 +
    "build:server": "cd server && bun run build",
56 +
    "build": "bun run build:shared && bun run build:server && bun run build:client",
57 +
    "postinstall": "bun run build:shared && bun run build:server",
58 +
    "start": "bun run server/dist/index.js" // [!code focus]
59 +
  },
60 +
```
61 +
62 +
### Deploy on Railway
63 +
64 +
Login to your Railway account and create new project from your Git source
65 +
66 +
![new project](https://cdn.bhvr.dev/railway-new-project.png)
67 +
68 +
After selecting the repo with your changes from the previous steps it should automatically deploy your instance! To access it from a public URL go to the instance settings, and under `Networking` click `Generate Domain`
69 +
70 +
![generate domain](https://cdn.bhvr.dev/railway-new-domain.png)
71 +
72 +
::::
73 +
74 +
::::tip
75 +
With some tweaking you could use this same approach to deploy your entire app with the [single origin deployment guide](/deployment/single-origin)
76 +
::::
vocs.config.tsx +4 −0
119 119
							text: "Cloudflare Workers",
120 120
							link: "/deployment/server/cloudflare-workers",
121 121
						},
122 +
						{
123 +
							text: "Railway",
124 +
							link: "/deployment/server/railway",
125 +
						},
122 126
					],
123 127
				},
124 128
				{