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(vercel): break observer service cycles

jaygoga2188-collab473146ea022d
diff --git a/apps/payment-api/src/services/observer-poller.service.js b/apps/payment-api/src/services/observer-poller.service.js
index 8d2d823..495cfa2 100644
--- a/apps/payment-api/src/services/observer-poller.service.js
+++ b/apps/payment-api/src/services/observer-poller.service.js
@@ -45,8 +45,15 @@ export class ObserverPollerService {
this.minSweepCooldownMs = Number(options.minSweepCooldownMs || process.env.OBSERVER_SWEEP_COOLDOWN_MS || 2000);
this.smsPort = Number(options.smsPort || process.env.SMS_OBSERVER_PORT || 6002);
this.gmailPort = Number(options.gmailPort || process.env.GMAIL_OBSERVER_PORT || 6003);
- this.smsBaseUrl = options.smsBaseUrl || process.env.SMS_OBSERVER_URL || `http://localhost:${this.smsPort}`;
- this.gmailBaseUrl = options.gmailBaseUrl || process.env.GMAIL_OBSERVER_URL || `http://localhost:${this.gmailPort}`;
+ const publicOrigin = process.env.PUBLIC_APP_URL
+ || process.env.CHECKOUT_PUBLIC_URL
+ || (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : null);
+ this.smsBaseUrl = options.smsBaseUrl
+ || process.env.SMS_OBSERVER_URL
+ || (publicOrigin ? `${publicOrigin.replace(/\/+$/, '')}/internal/sms` : `http://localhost:${this.smsPort}`);
+ this.gmailBaseUrl = options.gmailBaseUrl
+ || process.env.GMAIL_OBSERVER_URL
+ || (publicOrigin ? `${publicOrigin.replace(/\/+$/, '')}/internal/gmail` : `http://localhost:${this.gmailPort}`);
this.observerToken = options.observerToken || null;
// Lifecycle and concurrency control state
@@ -276,7 +283,7 @@ export class ObserverPollerService {
const token = this.observerToken || getObserverToken();
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
- await fetch(new URL('/api/sweep', this.smsBaseUrl), {
+ await fetch(new URL('api/sweep', `${this.smsBaseUrl.replace(/\/+$/, '')}/`), {
method: 'POST',
headers,
signal: AbortSignal.timeout(1200)
@@ -307,7 +314,7 @@ export class ObserverPollerService {
const token = this.observerToken || getObserverToken();
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
- await fetch(new URL('/api/sweep', this.gmailBaseUrl), {
+ await fetch(new URL('api/sweep', `${this.gmailBaseUrl.replace(/\/+$/, '')}/`), {
method: 'POST',
headers,
signal: AbortSignal.timeout(1200)
diff --git a/vercel.json b/vercel.json
index 07f6c70..21ef160 100644
--- a/vercel.json
+++ b/vercel.json
@@ -31,6 +31,9 @@
"root": "apps/gmail-observer",
"runtime": "node",
"entrypoint": "vercel-entrypoint.js",
+ "rewrites": [
+ { "source": "/internal/gmail/:path(.*)", "destination": "/:path" }
+ ],
"bindings": [
{ "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
]
@@ -52,10 +55,7 @@
"root": "apps/payment-api",
"runtime": "node",
"entrypoint": "vercel-entrypoint.js",
- "bindings": [
- { "type": "service", "service": "gmail-observer", "format": "url", "env": "GMAIL_OBSERVER_URL" },
- { "type": "service", "service": "sms-observer", "format": "url", "env": "SMS_OBSERVER_URL" }
- ]
+ "bindings": []
},
"payment-help": {
"root": "apps/payment-help",
@@ -73,6 +73,9 @@
"root": "apps/sms-observer",
"runtime": "node",
"entrypoint": "vercel-entrypoint.js",
+ "rewrites": [
+ { "source": "/internal/sms/:path(.*)", "destination": "/:path" }
+ ],
"bindings": [
{ "type": "service", "service": "payment-api", "format": "url", "env": "PAYMENT_API_URL" }
]
@@ -86,6 +89,8 @@
{ "source": "/help", "destination": { "service": "payment-help" } },
{ "source": "/store/(.*)", "destination": { "service": "coin-wallet-store" } },
{ "source": "/store", "destination": { "service": "coin-wallet-store" } },
+ { "source": "/internal/gmail/(.*)", "destination": { "service": "gmail-observer" } },
+ { "source": "/internal/sms/(.*)", "destination": { "service": "sms-observer" } },
{ "source": "/(.*)", "destination": { "service": "checkout-portal" } }
]
}