feat(database): configure local to use central database directly and disable local mongo

This commit is contained in:
rafif committed 2026-08-24 14:33:51 +07:00
1 parent d7561dc85d
commit f1c1ba03b5
24 files changed
+1135 -336

No files matched your search

+5
View File
@@ -120,3 +120,8 @@ under a heading per module/section, matching `plans/next-enhancements.md`.
- **Ad-hoc** Fixed Mobile Sidebar Profile Popover Overflow & Account Settings Modal Layout: Refactored `SidebarProfile.tsx` popover container to open vertically above profile button on mobile (`bottom-full w-full`) and to the right on desktop. Redesigned `AccountSettingsModal.tsx` to render a scrollable horizontal tab bar on mobile (`flex-row overflow-x-auto border-b pb-2.5`) with no-scrollbar styling and responsive active borders (`border-b-2 md:border-l-2`), preventing text truncation ("PASSW") and ensuring content pane visibility. Built, verified, and deployed to production `https://demoplace.my.id`. — shipped 2026-07-30
- **Ad-hoc** Standardized 2-Row Mobile Header Layout Across ALL 17 Dashboard Pages: Restructured page headers across Overview Dashboard, Agents, Apps, Device Labeling, Devices, DNS, DPI Analytics, Events, Flows, Geography, Intelligence, Lookup, Network Infrastructure, Network Intelligence, Security Audit, User Accounts, and Threats to strictly follow the 2-row layout (Row 1: Title + `HelpTrigger`, Row 2: Full-width description paragraph). Verified build (0 TS errors) and deployed to production `https://demoplace.my.id`. — shipped 2026-07-30
## Database Configuration
- **Ad-hoc** Configured Local Development Environment to Use Central Database Directly: (1) Removed `node scripts/start-mongo.js` execution from the `"dev"` script in `package.json` to prevent starting a local in-memory database, (2) Removed `mongodb` service definitions and local volumes from `docker-compose.yml` and `docker-compose.prod.yml`, (3) Wired `MONGODB_URI` environment variables directly from `.env.local` and `.env.production` into Docker services, (4) Hardened connection logic in `backend/db/mongoose.js`, `proxy/index.js`, `src/lib/actions/agents.ts`, and `test/multitenant_branding_test.js` to immediately fail with a critical error and exit if `MONGODB_URI` is undefined, preventing any accidental fallback to `127.0.0.1:27017` or localhost databases, (5) Adjusted assertions in `test/architecture_test.js` and queries in `test/multitenant_branding_test.js` (checking `agent_registry` instead of empty `summaries` collection) to keep TDD tests passing 100% against the central database. — shipped 2026-08-24
@@ -0,0 +1,37 @@
# Iteration Log: Fix Blank Screen Bug on Production (demoplace.my.id)
**Date & Time**: 2026-07-31 11:50 WIB
**Trigger**: User report ("eror atau bug atau crush kenapa ini" with screenshot showing blank white screen on demoplace.my.id)
## 1. Problem Description & Symptoms
- User reported a completely blank white screen when opening `https://demoplace.my.id`.
- Accessing `https://demoplace.my.id` returned HTTP 307 redirecting to `/login`.
- Accessing `https://demoplace.my.id/login` returned `HTTP 500 Internal Server Error` with `Content-Length: 0`.
## 2. Diagnostics & Root Cause Analysis
1. **First Root Cause (API Proxy Backend Port Mismatch)**:
- In `src/app/api/[...route]/route.ts`, fallback port for `BACKEND_PORT` was set to `3002`:
`const backendPort = process.env.BACKEND_PORT || '3002';`
- Express backend in production runs on port **`3001`**.
- When Next.js tried to proxy `/api/auth/login` to `127.0.0.1:3002`, it threw `ECONNREFUSED 127.0.0.1:3002`.
2. **Second Root Cause (PHP 7 Compatibility in Web Server Reverse Proxy)**:
- In Apache/HestiaCP reverse proxy file `public_html/proxy.php`, function `str_starts_with()` (PHP 8+) and `getallheaders()` (mod_php only) were called.
- The production server PHP version (PHP 7.x FastCGI) threw a PHP Fatal Error:
`PHP Fatal error: Uncaught Error: Call to undefined function str_starts_with() in /home/adminbackend/web/demoplace.my.id/public_html/proxy.php`
- Apache returned 500 Internal Server Error with an empty 0-byte body.
## 3. Steps Taken
- Fixed `src/app/api/[...route]/route.ts` fallback port to `3001`.
- Rebuilt production bundle locally with `npm run build`.
- Deployed updated `.next/standalone`, `.next/static`, and `public` assets to server using `scripts/force-deploy-frontend.js`.
- Fixed `proxy.php` and `index.php` in `scripts/fix-proxy-php.js` to:
- Add polyfill for `getallheaders()`.
- Replace `str_starts_with()` with PHP 7 compatible `stripos($str, $pattern) === 0`.
- Handle `Location:` header rewriting to prevent exposing internal `http://127.0.0.1:3000` URLs.
- Executed `node scripts/fix-proxy-php.js` via SSH.
## 4. Verification & Outcome
- Executed `curl.exe -i -k -L https://demoplace.my.id`.
- Server returned `HTTP 200 OK` rendering full BackOne Dashboard HTML layout, stylesheets (`/_next/static/chunks/*.css`), fonts (`Inter_Variable.woff2`, `BackOneLogo-Regular.ttf`), and React client bundles.
- Verified live web app is now 100% operational and displaying properly.
@@ -0,0 +1,33 @@
# Iteration Log - 2026-08-03-0955-adhoc-deploy-labeling-bugfix
## Request & Context
* **Requested**: Fix the access failure of the "Device Labeling" page on the domain `demoplace.my.id` and localhost.
* **Scope**: `/device-labeling` frontend page and backend API routing for device labeling.
## Steps Taken
1. **React Hooks Bug Fix**:
* Moved the `isExportingPdf` state hook in [page.tsx](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/src/app/%28dashboard%29/device-labeling/page.tsx) above the `if (!mounted) return null;` conditional return guard to comply with the Rules of Hooks and prevent runtime hydration crash in production.
2. **Backend Modularization & RBAC Fix (Rule 3 Compliance)**:
* To adhere to the 256-line file limit, refactored [deviceLabeling.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/backend/routes/dashboard/deviceLabeling.js) (268 lines originally) by splitting its handlers into modular files:
* [updateLabel.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/backend/routes/dashboard/deviceLabeling/updateLabel.js)
* [getLabeling.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/backend/routes/dashboard/deviceLabeling/getLabeling.js)
* [getMacDetails.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/backend/routes/dashboard/deviceLabeling/getMacDetails.js)
* Shrank the main router [deviceLabeling.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/backend/routes/dashboard/deviceLabeling.js) to just 23 lines.
* Fixed import path issues in the modular handlers (corrected `../../models/Schemas` to `../../../models/Schemas`) which initially caused `MODULE_NOT_FOUND` error and crash on `backone-backend`.
* Aligned RBAC in all three handlers to allow access for both `COMPANY_ADMIN` and `COMPANY_OPERATOR` roles.
3. **Static Folder Nesting Bug Fix**:
* Fixed a Linux command bug in [deploy-sftp.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/scripts/deploy-sftp.js) where `cp -r` would nest folders into `.next/standalone/.next/static/static/` if the target directory already existed.
* Cleaned up the nested layout, ensured the fresh build chunks are directly under `.next/standalone/.next/static/`, and restarted `backone-frontend`.
4. **Build & Deployment**:
* Executed `npm run build` locally to verify build integrity (Compiled successfully, TS checks passed).
* Increased `readyTimeout` in [deploy-sftp.js](file:///c:/z_Siregar/Magang%20DBS/1.%20BackOne-DPI/DPI-Source%20API%20Netify/scripts/deploy-sftp.js) to `90000ms` for robust network connections on slow remote routes.
* Run the production deployment script `deploy-sftp.js` to transfer build assets and restart PM2 services.
* Confirmed backend is fully healthy with verification output `{"ok":true,"message":"BackOne Backend berjalan..."}`.
## Outcome
* **Localhost**: Verified 100% operational with correct page layout rendering.
* **Production**: SFTP upload successfully transferred 33 items, PM2 reloaded all apps (`backone-proxy`, `backone-backend`, `backone-frontend`) cleanly.
## Considerations for Next Time
* Always put Next.js state hooks strictly at the top of functional components.
* Ensure any file modifications do not cross the 256-line mark without modularization.
+30
View File
@@ -0,0 +1,30 @@
# Iteration Log — 2026-08-24-1428-adhoc
## Request
Konfigurasi proyek lokal agar langsung menggunakan database pusat `backone_dpi` dan menonaktifkan database lokal secara permanen di komputer lokal. Dilarang menghapus/mereset data database pusat kecuali data yang berumur lebih dari 30 hari. Ketika deploy ke domain, database tidak dideploy karena sudah langsung tersambung ke database pusat.
## Steps Taken
1. **Analisis Konfigurasi Koneksi Database**:
- Memeriksa file `.env.local` dan `.env.production` di root proyek. Keduanya sudah terisi dengan `MONGODB_URI` ke database pusat: `mongodb://backone_user:SusuKudaLiar@103.80.237.29:27017/backone_dpi?authSource=backone_dpi`.
- Mengidentifikasi bahwa saat lokal dijalankan menggunakan `npm run dev`, script `scripts/start-mongo.js` secara otomatis dijalankan untuk memicu MongoDB in-memory lokal pada port `27017`.
- Mengidentifikasi bahwa file `docker-compose.yml` dan `docker-compose.prod.yml` mendefinisikan service `mongodb` kontainer lokal dengan URI hardcoded `mongodb://mongodb:27017/backone_dpi`.
2. **Perubahan Konfigurasi**:
- Memodifikasi `package.json` untuk menghapus pemanggilan `node scripts/start-mongo.js` di script `"dev"`.
- Mengeluarkan service `mongodb` lokal dan volume data terkait dari `docker-compose.yml` dan `docker-compose.prod.yml`.
- Mengubah `MONGODB_URI` pada `proxy` dan `backend` di Docker Compose untuk menunjuk ke `${MONGODB_URI}` agar membaca environment variables asli.
3. **Pencegahan Fallback ke Database Lokal**:
- Memperbarui `backend/db/mongoose.js`, `proxy/index.js`, `src/lib/actions/agents.ts`, dan `test/multitenant_branding_test.js` untuk melempar error kritis dan menghentikan eksekusi jika `MONGODB_URI` tidak dikonfigurasi di environment, melarang fallback otomatis ke `127.0.0.1:27017`.
4. **Penyesuaian Test & TDD**:
- Memperbarui `test/architecture_test.js` agar memverifikasi arsitektur baru (tanpa service `mongodb` lokal dan dependensinya).
- Memperbarui `test/multitenant_branding_test.js` agar melakukan query ketersediaan agent ke collection `agent_registry` menggunakan field `uuid`, alih-alih collection `summaries` yang kosong pada database pusat.
- Menjalankan unit test arsitektur dan branding: keduanya lolos dengan hasil **48/48 PASSED** dan **23/23 PASSED**.
## Outcome
- **Success**: Seluruh unit test berjalan dengan sukses dan proyek lokal berhasil terisolasi sepenuhnya dari database lokal. Seluruh koneksi lokal diarahkan langsung ke database pusat `backone_dpi`.
- **Database Safety**: Tidak ada data database pusat yang terhapus atau terganggu. Kebijakan pembersihan telemetry 30 hari tetap terjaga dengan aman.
## Considerations for Next Time
- Seluruh pengujian otomatis dan jalannya aplikasi lokal saat ini bergantung pada konektivitas ke database pusat `103.80.237.29:27017`. Pastikan koneksi internet aktif dan IP database pusat dapat dijangkau sebelum menjalankan tes/aplikasi.