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(control-center): honor configured port in gateway launchers
Samir Hanna Verza56bfc96e8530
diff --git a/scripts/control-center-port.test.js b/scripts/control-center-port.test.jsnew file mode 100644index 0000000..6a68da7--- /dev/null+++ b/scripts/control-center-port.test.js@@ -0,0 +1,92 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { spawnSync } from 'node:child_process';++const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');++function runLauncher(t, script, { port, dotenvPort } = {}) {+ const fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'youpi-control-port-'));+ t.after(() => fs.rmSync(fixture, { recursive: true, force: true }));+ function write(relativePath, contents) {+ const target = path.join(fixture, relativePath);+ fs.mkdirSync(path.dirname(target), { recursive: true });+ fs.writeFileSync(target, contents);+ }+ write('package.json', '{"type":"module"}');+ // Exercise the real entrypoint and existing port resolver; substitute only+ // database/service startup and the listener so tests never claim shared ports.+ for (const relativePath of [+ `scripts/${script}`,+ 'apps/control-center/src/index.js',+ 'packages/common/src/runtime-config.js'+ ]) {+ write(relativePath, fs.readFileSync(path.join(rootDir, relativePath), 'utf8'));+ }+ write('packages/db/src/migrate.js', `+ export function runMigrations() {+ return { defaultMerchant: { businessName: 'Port fixture', branding: {} } };+ }+ `);+ write('packages/common/src/tunnel-command.js', `+ export function startCloudflaredSafely() { throw new Error('Unexpected tunnel startup'); }+ `);+ write('apps/control-center/src/process-manager.js', `+ export class ProcessManager {+ async startAll() { console.log('SERVICES_STARTED'); }+ async stopAll() {}+ }+ `);+ write('apps/control-center/src/server.js', `+ export class ControlCenterServer {+ createServer() {+ return {+ listen(port, host, ready) {+ console.log('LISTEN_ARGUMENTS ' + JSON.stringify({ port, host }));+ queueMicrotask(ready);+ return { close(done) { done(); } };+ }+ };+ }+ }+ `);+ if (dotenvPort !== undefined) write('.env', `CONTROL_CENTER_PORT=${dotenvPort}\n`);+ const env = { ...process.env };+ for (const key of Object.keys(env)) {+ if (/^(YOUPI_|CLOUDFLARE_|DEPLOYMENT_|NODE_)/.test(key) || key === 'CONTROL_CENTER_PORT') delete env[key];+ }+ env.CLOUDFLARE_DOMAIN = 'port-fixture.example';+ if (port !== undefined) env.CONTROL_CENTER_PORT = String(port);+ const result = spawnSync(process.execPath, [path.join(fixture, 'scripts', script)], {+ cwd: fixture, env, encoding: 'utf8', timeout: 10000+ });+ assert.equal(result.status, 0, result.error?.message || result.stderr || result.stdout);+ const listenLine = result.stdout.split('\n').find(line => line.startsWith('LISTEN_ARGUMENTS '));+ assert.ok(listenLine, result.stdout);+ assert.match(result.stdout, /SERVICES_STARTED/);+ return { ...JSON.parse(listenLine.slice('LISTEN_ARGUMENTS '.length)), output: result.stdout };+}++for (const script of ['dev.js', 'start.js']) {+ test(`${script} honors CONTROL_CENTER_PORT from its process environment`, t => {+ const result = runLauncher(t, script, { port: 18090 });+ assert.equal(result.port, 18090);+ assert.equal(result.host, '127.0.0.1');+ assert.match(result.output, /Control Center is online at: http:\/\/localhost:18090/);+ });++ test(`${script} keeps the default control-center port when none is configured`, t => {+ assert.equal(runLauncher(t, script).port, 8090);+ });+}++test('start.js honors CONTROL_CENTER_PORT loaded from the project .env', t => {+ assert.equal(runLauncher(t, 'start.js', { dotenvPort: 18091 }).port, 18091);+});++test('start.js keeps an explicit process port ahead of the .env fallback', t => {+ assert.equal(runLauncher(t, 'start.js', { port: 18092, dotenvPort: 18091 }).port, 18092);+});diff --git a/scripts/dev.js b/scripts/dev.jsindex 7efc513..1f561cb 100644--- a/scripts/dev.js+++ b/scripts/dev.js@@ -29,10 +29,10 @@ if (tunnelCmd && tunnelCmd.trim()) {}// 2. Start Control Center supervisor and launch all services-console.log('[2/2] Launching Local Process Control Center on port 8090...');-const cc = await startControlCenter(8090);+console.log('[2/2] Launching Local Process Control Center...');+const cc = await startControlCenter();-console.log('\n[✓] Control Center is online at: http://localhost:8090');+console.log(`\n[✓] Control Center is online at: http://localhost:${cc.port}`);console.log('[*] Starting all modular gateway services...\n');await cc.processManager.startAll();diff --git a/scripts/start.js b/scripts/start.jsindex ffe3ee1..e7b73c8 100644--- a/scripts/start.js+++ b/scripts/start.js@@ -93,8 +93,9 @@ if (tunnelCmd && tunnelCmd.trim()) {}// 3. Launch Process Supervisor and Production Services-console.log('[2/3] Launching Local Process Supervisor on port 8090...');-const cc = await startControlCenter(8090);+console.log('[2/3] Launching Local Process Supervisor...');+const cc = await startControlCenter();+console.log(`\n[✓] Control Center is online at: http://localhost:${cc.port}`);console.log('[3/3] Starting core production gateway services (Pure API & Android Observer)...\n');await cc.processManager.startAll();diff --git a/scripts/test-all.js b/scripts/test-all.jsindex 65ccf0e..6cbc72b 100644--- a/scripts/test-all.js+++ b/scripts/test-all.js@@ -31,6 +31,7 @@ const testFiles = ['apps/sms-observer/src/__tests__/sms-observer.test.js','apps/android-observer-app/__tests__/android-observer.test.js','apps/control-center/src/__tests__/control-center.test.js',+ 'scripts/control-center-port.test.js','apps/payment-api/src/__tests__/payment-api.test.js','apps/payment-api/src/__tests__/auth-guard.test.js','apps/payment-api/src/__tests__/counter-payments.test.js',