diff --git a/src/app/api/v1/stock-purchases/[id]/send-email/route.ts b/src/app/api/v1/stock-purchases/[id]/send-email/route.ts index f143063..5f1bdac 100644 --- a/src/app/api/v1/stock-purchases/[id]/send-email/route.ts +++ b/src/app/api/v1/stock-purchases/[id]/send-email/route.ts @@ -91,7 +91,12 @@ export async function POST( const { getAdminPocketBase } = await import("@/lib/server/pocketbase-admin"); const adminPb = await getAdminPocketBase(); const pbUrl = process.env.NEXT_PUBLIC_POCKETBASE_URL || process.env.PB_URL || ""; - const dashboardBaseUrl = req.nextUrl.origin; + // Build the callback base URL from DASHBOARD_URL — NOT + // `req.nextUrl.origin`. Inside the Next.js process the origin + // resolves to the bind address (e.g. `0.0.0.0:3000`), which the + // n8n container can't reach. DASHBOARD_URL is the same env var + // the customer-PO route uses for this purpose. + const dashboardBaseUrl = (process.env.DASHBOARD_URL || "").replace(/\/+$/, ""); if (result.failure) { return NextResponse.json(