Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

fix(docker): make the container start, and tighten the published surface

rishabh90eecd58cfa0
diff --git a/Dockerfile b/Dockerfile
index 6744963..9313d01 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,7 +4,7 @@
# =============================================================================
# ── Stage 0: Base ────────────────────────────────────────────────────────────
-FROM node:24-alpine AS base
+FROM node:24-alpine@sha256:429bdfbc204b4eabc6438e6d34e4e9d8dd2ca1df8289bcd78cdd3c5db387b7a5 AS base
RUN apk update && apk upgrade --no-cache && apk add --no-cache libc6-compat
WORKDIR /app
@@ -29,8 +29,11 @@ COPY apps/coin-wallet-store/package.json ./apps/coin-wallet-store/
COPY apps/payment-help/package.json ./apps/payment-help/
COPY apps/android-observer-app/package.json ./apps/android-observer-app/
-# Clean installation of dependencies with script safety
-RUN npm ci --ignore-scripts
+# Clean installation of dependencies. Install scripts stay disabled during `npm ci` so no
+# arbitrary third-party postinstall code runs during the build, then better-sqlite3's native
+# binding is compiled explicitly: it is a transitive dependency of the WhatsApp Berry SDK and
+# has no prebuilt binary for this platform, so skipping it leaves that feature broken.
+RUN npm ci --ignore-scripts && npm rebuild better-sqlite3
# ── Stage 2: Builder ────────────────────────────────────────────────────────
FROM deps AS builder
diff --git a/docker-compose.yml b/docker-compose.yml
index e0e424a..7539882 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -23,6 +23,10 @@ services:
environment:
NODE_ENV: ${NODE_ENV:-production}
YOUPI_MODE: ${YOUPI_MODE:-localhost}
+ # The container ships without a Cloudflare domain, so localhost mode is requested
+ # explicitly rather than being an implicit fallback. scripts/start.js still refuses to
+ # run in production mode without a domain.
+ YOUPI_ALLOW_LOCALHOST_MODE: ${YOUPI_ALLOW_LOCALHOST_MODE:-true}
YOUPI_BIND_HOST: "0.0.0.0"
BASE_PAYMENT_API_URL: http://localhost:6100
BASE_CHECKOUT_URL: http://localhost:7000
@@ -37,13 +41,18 @@ services:
COIN_WALLET_STORE_PORT: 5000
CONTROL_CENTER_PORT: 8090
ports:
+ # Public surfaces. These are the ports meant to be reachable (and are the ones the
+ # Cloudflare Tunnel targets).
- "6100:6100" # Payment Core REST API
- "7000:7000" # Checkout Portal
- - "6001:6001" # Merchant Admin Dashboard
- - "6002:6002" # Android SMS Observer
- - "6003:6003" # Gmail Observer
- "5000:5000" # Coin Wallet Demo Store
- - "8090:8090" # Process Supervisor Daemon
+ # Operator surfaces. Bound to loopback on the host: the Merchant Admin holds admin
+ # credentials and the Control Center can start/stop every service and stream their
+ # logs. Publish them on 0.0.0.0 only if the host is not directly reachable.
+ - "127.0.0.1:6001:6001" # Merchant Admin Dashboard
+ - "127.0.0.1:6002:6002" # Android SMS Observer
+ - "127.0.0.1:6003:6003" # Gmail Observer
+ - "127.0.0.1:8090:8090" # Process Supervisor Daemon
volumes:
- youpi-data:/app/data
healthcheck:
diff --git a/scripts/start.js b/scripts/start.js
index bade2fa..ffe3ee1 100644
--- a/scripts/start.js
+++ b/scripts/start.js
@@ -19,14 +19,31 @@ try {
}
} catch {}
-// Authoritative runtime mode enforcement (start.js takes absolute precedence)
-process.env.YOUPI_MODE = 'production';
-process.env.NODE_ENV = 'production';
-
-
-console.log('====================================================');
-console.log('🚀 Starting YOUPI PG V2 — Production Gateway');
-console.log('====================================================');
+// Authoritative runtime mode enforcement (start.js takes absolute precedence).
+//
+// Production is the default and the ONLY mode that requires a Cloudflare domain: nothing
+// ever falls back to localhost implicitly. A containerised or LAN-only deployment can
+// opt out EXPLICITLY with YOUPI_ALLOW_LOCALHOST_MODE=true together with
+// YOUPI_MODE=localhost, so the operator has asked for it rather than it being a silent
+// fallback.
+const allowLocalhostMode = String(process.env.YOUPI_ALLOW_LOCALHOST_MODE || '').trim().toLowerCase() === 'true';
+const requestedMode = String(process.env.YOUPI_MODE || '').trim().toLowerCase();
+const runInLocalhostMode = allowLocalhostMode && requestedMode === 'localhost';
+
+if (runInLocalhostMode) {
+ console.log('\n====================================================');
+ console.log('🚀 Starting YOUPI PG V2 — Localhost Mode (explicit opt-in)');
+ console.log('====================================================');
+ process.env.YOUPI_MODE = 'localhost';
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
+} else {
+ process.env.YOUPI_MODE = 'production';
+ process.env.NODE_ENV = 'production';
+
+ console.log('\n====================================================');
+ console.log('🚀 Starting YOUPI PG V2 — Production Gateway');
+ console.log('====================================================');
+}
// 1. Run database migrations & load persisted configuration (Part B3: never overwrite settings)
console.log('[1/3] Loading persisted production database & settings...');
@@ -38,7 +55,7 @@ const branding = merchant?.branding || {};
const domain = (branding.cloudflareDomain || branding.domainTld || process.env.CLOUDFLARE_DOMAIN || '').trim().toLowerCase().replace(/^https?:\/\//, '').replace(/\/+$/, '');
const prefix = (branding.deploymentPrefix || branding.domainPrefix || process.env.DEPLOYMENT_PREFIX || 'pay').trim().toLowerCase().replace(/[^a-z0-9-_]/g, '') || 'pay';
-if (!domain) {
+if (!domain && !runInLocalhostMode) {
console.error('\n================================================================');
console.error('❌ [CONFIGURATION ERROR] PRODUCTION STARTUP FAILED');
console.error('================================================================');
@@ -54,14 +71,14 @@ if (!domain) {
let runtimeUrls;
try {
- runtimeUrls = resolveRuntimeUrls({ envMode: 'production', domain, prefix });
+ runtimeUrls = resolveRuntimeUrls({ envMode: runInLocalhostMode ? 'localhost' : 'production', domain, prefix });
} catch (err) {
console.error('\n❌ [CONFIGURATION ERROR]:', err.message);
process.exit(1);
}
-console.log(`[✓] Authoritative Runtime Mode: PRODUCTION`);
-console.log(`[✓] Cloudflare Domain: ${runtimeUrls.domain}`);
+console.log(`[✓] Authoritative Runtime Mode: ${runInLocalhostMode ? 'LOCALHOST (explicit opt-in)' : 'PRODUCTION'}`);
+console.log(`[✓] ${runInLocalhostMode ? 'Public Host' : 'Cloudflare Domain'}: ${runtimeUrls.domain}`);
console.log(`[✓] Deployment Prefix: ${runtimeUrls.prefix}\n`);
// Check for user-configured Cloudflare Tunnel command
@@ -83,9 +100,11 @@ console.log('[3/3] Starting core production gateway services (Pure API & Android
await cc.processManager.startAll();
console.log('====================================================');
-console.log('🟢 YOUPI PG V2 PRODUCTION GATEWAY ONLINE & ACTIVE');
+console.log(runInLocalhostMode
+ ? '🟢 YOUPI PG V2 GATEWAY ONLINE & ACTIVE (localhost mode)'
+ : '🟢 YOUPI PG V2 PRODUCTION GATEWAY ONLINE & ACTIVE');
console.log('====================================================');
-console.log('AUTHORITATIVE PUBLIC CLOUDFLARE ROUTES:');
+console.log(runInLocalhostMode ? 'LOCAL SERVICE ROUTES:' : 'AUTHORITATIVE PUBLIC CLOUDFLARE ROUTES:');
console.log(`• Checkout Portal: ${runtimeUrls.checkoutUrl} (-> :7000)`);
console.log(`• Payment Core API: ${runtimeUrls.apiUrl} (-> :6100)`);
console.log(`• Merchant Admin Hub: ${runtimeUrls.adminUrl} (-> :6001)`);
@@ -95,7 +114,9 @@ console.log('----------------------------------------------------');
console.log('OBSERVATION CHANNELS:');
console.log('• Android SMS Observer: Native APK -> Public Payment API');
console.log('• Gmail API Observer: OAuth2 API -> Public Payment API');
-console.log('• Legacy Chrome CDP: DISABLED in production');
+console.log(runInLocalhostMode
+ ? '• Legacy Chrome CDP: ENABLED in localhost mode'
+ : '• Legacy Chrome CDP: DISABLED in production');
console.log('====================================================');
console.log('Press Ctrl+C to stop all services gracefully.');