在 Render 上部署 Bun 應用
Render 是一個用於建置、部署和擴充套件應用的雲平臺。
它提供來自 GitHub 的自動部署、全球 CDN、私有網路、自動 HTTPS 設定,以及託管的 PostgreSQL 和相容 Redis 的 Key Value 儲存。
Render 原生支援 Bun。你可以將 Bun 應用作為 Web 服務、後臺工作行程、定時任務等進行部署。
作為範例,本指南將 Express HTTP 伺服器部署到 Render。
- 步驟 1
建立一個名為
myapp的新的 GitHub 儲存庫。將其克隆到本地。shellgit clone git@github.com:my-github-username/myapp.git cd myapp - 步驟 2
新增 Express 庫。
shellbun add express - 步驟 3
使用 Express 定義一個伺服器:
app.ts
import express from "express"; const app = express(); const port = process.env.PORT || 3001; app.get("/", (req, res) => { res.send("Hello World!"); }); app.listen(port, () => { console.log(`Listening on port ${port}...`); }); - 步驟 4
提交你的更改並推送到 GitHub。
terminalgit add app.ts bun.lock package.json git commit -m "Create simple Express app" git push origin main - 步驟 5
在你的 Render 控制面板 中,點選
New>Web Service並連線你的myapp儲存庫。 - 步驟 6
在 Render 介面中,建立 Web 服務時填寫以下內容:
執行環境 (Runtime) Node建置命令 (Build Command) bun install啟動命令 (Start Command) bun app.ts
建置完成後,你的 Web 服務就會通過分配的 onrender.com URL 上線。