Deployment
Build Produksi
Section titled “Build Produksi”bun run buildPerintah ini menghasilkan direktori dist/ yang berisi:
dist/server/— entry point serverdist/client/— bundle JavaScript dan CSS kliendist/prerendered/— HTML statis untuk rute yang telah di-prerender
Menjalankan di Produksi
Section titled “Menjalankan di Produksi”bun run startAtau secara langsung:
bun dist/server/index.jsAtur port dengan variabel lingkungan PORT (default: 9000).
Health Check
Section titled “Health Check”Bosia mengekspos endpoint health di /_health:
curl http://localhost:9000/_health{ "status": "ok", "timestamp": 1711360000000, "timezone": "UTC" }Prerendering
Section titled “Prerendering”Tandai rute untuk prerendering statis:
export const prerender = true;Halaman yang di-prerender dibuat sebagai HTML statis selama bosia build dan disajikan dari dist/prerendered/ dengan cache header 1 jam.
Caching Aset Statis
Section titled “Caching Aset Statis”Bosia mengatur cache header secara otomatis:
| Tipe Aset | Cache Header |
|---|---|
| Nama file dengan hash | public, max-age=31536000, immutable |
| File tanpa hash | no-cache |
Graceful Shutdown
Section titled “Graceful Shutdown”Server produksi menangani sinyal SIGTERM dan SIGINT:
- Berhenti menerima koneksi baru
- Menunggu request yang sedang berjalan untuk selesai
- Memaksa keluar setelah 10 detik jika proses shutdown terhenti
Docker
Section titled “Docker”Contoh Dockerfile:
FROM oven/bun:1 AS baseWORKDIR /app
# Install dependenciesFROM base AS depsCOPY package.json bun.lock ./RUN bun install --frozen-lockfile
# BuildFROM deps AS buildCOPY . .RUN bun run build
# ProductionFROM base AS runtimeCOPY --from=deps /app/node_modules ./node_modulesCOPY --from=build /app/dist ./distCOPY --from=build /app/package.json ./
ENV NODE_ENV=productionENV PORT=9000EXPOSE 9000
CMD ["bun", "dist/server/index.js"]Variabel Lingkungan
Section titled “Variabel Lingkungan”Lihat Variabel Lingkungan untuk daftar lengkap opsi konfigurasi termasuk PORT, BODY_SIZE_LIMIT, CORS, dan pengaturan CSRF.