From 9e8f4fabcbb4bff92db7c25b9501ccf0fe950724 Mon Sep 17 00:00:00 2001 From: Wira Irawan Date: Mon, 11 May 2026 14:21:18 +0700 Subject: [PATCH] Separate frontend app API from backend API in production --- .env.example | 2 +- deploy/debian12/README.md | 15 ++++++++- deploy/debian12/app.env.example | 4 +-- deploy/debian12/nginx.portal.bizone.id.conf | 35 ++++++++++++++++----- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 6d360ff..6721380 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ WEBHOOK_VERIFY_TOKEN=replace-with-32-plus-char-random-token WEBHOOK_SHARED_SECRET=replace-with-32-plus-char-random-secret META_WEBHOOK_APP_SECRET= WEBHOOK_ALLOW_UNSIGNED=false -NEXT_PUBLIC_API_URL=http://localhost:3001/api +NEXT_PUBLIC_API_URL=http://localhost:3000/backend-api MAIL_HOST=mail.example.com MAIL_PORT=465 MAIL_SECURE=true diff --git a/deploy/debian12/README.md b/deploy/debian12/README.md index 9f2c42a..5a09ffa 100644 --- a/deploy/debian12/README.md +++ b/deploy/debian12/README.md @@ -11,7 +11,7 @@ Panduan ini menyiapkan `bizone-web` di server Debian 12 kosong dengan topologi b ## URL Production Final - Aplikasi: `https://portal.bizone.id` -- Backend API public base URL: `https://portal.bizone.id/api` +- Backend API browser/server base URL via reverse proxy: `https://portal.bizone.id/backend-api` - Health check backend: `https://portal.bizone.id/api/health` - Webhook verify URL Meta: `https://portal.bizone.id/api/webhooks/whatsapp` - Webhook event URL Meta: `https://portal.bizone.id/api/webhooks/whatsapp` @@ -26,6 +26,8 @@ Untuk integrasi Meta, gunakan URL default berikut: Catatan penting: - Route backend memakai global prefix `/api`, jadi endpoint controller `GET /webhooks/whatsapp` menjadi `GET /api/webhooks/whatsapp`. +- Di production, `nginx` mengekspos backend internal aplikasi lewat prefix `https://portal.bizone.id/backend-api`. +- Prefix `/api/*` di browser dipakai oleh route handler Next.js untuk operasi dashboard seperti save contact, save user, export, dan aksi client-side lain. - Jika Anda ingin verifikasi tanda tangan resmi dari Meta, isi `META_WEBHOOK_APP_SECRET`. - Bila `META_WEBHOOK_APP_SECRET` terisi, request ke `POST /api/webhooks/whatsapp/meta` menuntut header `x-hub-signature-256`. - Endpoint `POST /api/webhooks/whatsapp` tetap bisa dipakai untuk Meta bila Anda memilih verify token + shared secret non-Meta untuk test lain, tetapi untuk produksi Meta lebih aman menargetkan URL default callback dan menyimpan `META_WEBHOOK_APP_SECRET`. @@ -237,6 +239,7 @@ Uji HTTP lokal: ```bash curl -I http://portal.bizone.id curl http://portal.bizone.id/api/health +curl http://portal.bizone.id/backend-api/health ``` ## 10. Aktifkan HTTPS @@ -250,6 +253,7 @@ Setelah cert aktif, uji: ```bash curl -I https://portal.bizone.id curl https://portal.bizone.id/api/health +curl https://portal.bizone.id/backend-api/health ``` Respons health ideal: @@ -331,3 +335,12 @@ sudo systemctl is-active bizone-backend sudo systemctl is-active bizone-frontend docker compose -f /srv/bizone-web/deploy/debian12/docker-compose.infra.yml ps ``` +##+Q&xN$86LbSA