Implement backend API and database services in Docker setup

- Added a new `api` service for the NestJS backend, including health checks and dependencies on PostgreSQL, Redis, and MinIO.
- Introduced PostgreSQL and Redis services with health checks and configurations for data persistence.
- Added MinIO for S3-compatible object storage and a one-shot service to initialize required buckets.
- Updated the Nginx configuration to proxy requests to the new backend API and MinIO storage.
- Enhanced the Dockerfile to support the new API environment variables and configurations.
- Updated the `package.json` and `package-lock.json` to include new dependencies for QR code generation and other utilities.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Dorian
2026-02-12 20:14:39 +00:00
parent f19fd6feef
commit cdd24a5def
478 changed files with 55355 additions and 529 deletions

63
src/utils/mock.ts Normal file
View File

@@ -0,0 +1,63 @@
/**
* Centralised mock-mode flag.
*
* Rules:
* 1. VITE_USE_MOCK_DATA="true" → mock ON
* 2. VITE_USE_MOCK_DATA="false" → mock OFF (try real backend)
* 3. Unset / empty → fall back to import.meta.env.DEV
*
* If the user opted for real mode (rule 2) but the backend is
* unreachable, `initMockMode()` automatically flips USE_MOCK to
* true so the app remains usable. A console banner lets the dev
* know what happened.
*/
const explicit = import.meta.env.VITE_USE_MOCK_DATA
// Exported as `let` so initMockMode() can reassign it.
// ES module live-bindings ensure every importer sees the update.
export let USE_MOCK: boolean =
explicit === 'false'
? false
: explicit === 'true'
? true
: import.meta.env.DEV
/**
* Call once at app startup (before mounting).
* Pings the backend — if unreachable and USE_MOCK is false,
* flips USE_MOCK to true so the whole app falls back to mock data.
*/
export async function initMockMode(): Promise<void> {
// Nothing to check if mock is already on
if (USE_MOCK) return
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:4000'
try {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 2000)
await fetch(apiUrl, {
method: 'HEAD',
signal: controller.signal,
})
clearTimeout(timeout)
// Backend is reachable — keep USE_MOCK = false
console.log(
'%c✅ Backend connected at %s — real mode active',
'color: #22c55e; font-weight: bold',
apiUrl,
)
} catch {
// Backend is not reachable — flip to mock
USE_MOCK = true
console.warn(
'%c⚠ Backend not reachable at %s — auto-switching to mock mode.\n' +
' Start the backend (npm run dev:full) for real API/payments.',
'color: #f59e0b; font-weight: bold',
apiUrl,
)
}
}