docs/pages/deployment/server/railway.mdx 2.1 K raw
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": "turbo dev",
50
    "dev:client": "turbo dev --filter=client",
51
    "dev:server": "turbo dev --filter=server",
52
    "build": "turbo build",
53
    "build:client": "turbo build --filter=client",
54
    "build:server": "turbo build --filter=server",
55
    "lint": "turbo lint",
56
    "type-check": "turbo type-check",
57
    "test": "turbo test",
58
    "postinstall": "turbo build --filter=shared --filter=server",
59
    "start": "bun run server/dist/index.js" // [!code focus]
60
  },
61
```
62
63
### Deploy on Railway
64
65
Login to your Railway account and create new project from your Git source
66
67
![new project](https://cdn.bhvr.dev/railway-new-project.png)
68
69
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`
70
71
![generate domain](https://cdn.bhvr.dev/railway-new-domain.png)
72
73
::::
74
75
::::tip
76
With some tweaking you could use this same approach to deploy your entire app with the [single origin deployment guide](/deployment/single-origin/vps-docker)
77
::::