Correos: leer la URL publica en tiempo de ejecucion (APP_URL)

Next incrusta process.env.NEXT_PUBLIC_* en el bundle al compilar, tambien en
codigo de servidor y aun con clave calculada. La imagen de produccion se
construye sin NEXT_PUBLIC_APP_URL, asi que los links de los correos de cobro
quedaban fijos en http://localhost:3000. Ahora se lee APP_URL (variable de
servidor) al enviar. Compose de Coolify, .env.example y AGENTS.md actualizados.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
urieljareth
2026-10-26 15:16:44 -06:00
co-authored by Claude Opus 5.5
parent 5e2b784c24
commit 14526f92f2
5 changed files with 20 additions and 11 deletions
+13 -7
View File
@@ -28,8 +28,14 @@ import type { PagoRecurrente } from "@/generated/prisma/client";
// - al aprobar/rechazar: notificarVerificacion(pagoId) / notificarRechazo(pagoId)
// - cobranza de lo que sigue por pagar: enviarRecordatoriosPendientes()
const BASE_URL = process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
const PANEL_PAGOS = `${BASE_URL}/cliente/pagos`;
// URL publica para los links de correo, leida AL ENVIAR. No usar un nombre
// NEXT_PUBLIC_*: Next lo incrusta en el bundle durante el build (tambien en el
// servidor, incluso con clave calculada) y la imagen de produccion se construye
// sin ese valor, asi que el link quedaba fijo en "http://localhost:3000".
function panelPagos(): string {
const base = process.env.APP_URL || "http://localhost:3000";
return `${base.replace(/\/+$/, "")}/cliente/pagos`;
}
// Nombres, conceptos y motivos los captura una persona: no deben poder
// inyectar HTML en el correo.
@@ -144,7 +150,7 @@ export async function notificarCobrosNuevos(pagos: PagoRecurrente[]): Promise<vo
userId,
destino,
titulo,
plantilla(titulo, cuerpo, { texto: "Ver mis pagos", url: PANEL_PAGOS }),
plantilla(titulo, cuerpo, { texto: "Ver mis pagos", url: panelPagos() }),
texto,
{
titulo: plural ? `${lista.length} cobros nuevos` : "Nuevo cobro pendiente",
@@ -188,7 +194,7 @@ export async function notificarVerificacion(pagoId: string): Promise<void> {
userId,
destino,
titulo,
plantilla(titulo, cuerpo, { texto: "Ver mis pagos", url: PANEL_PAGOS }),
plantilla(titulo, cuerpo, { texto: "Ver mis pagos", url: panelPagos() }),
`${programa.concepto}: pago del ${formatFechaCorta(pago.fecha)} verificado.`,
{
titulo: "Pago verificado ✓",
@@ -223,7 +229,7 @@ export async function notificarRechazo(pagoId: string, motivo: string): Promise<
userId,
destino,
titulo,
plantilla(titulo, cuerpo, { texto: "Subir otro comprobante", url: PANEL_PAGOS }),
plantilla(titulo, cuerpo, { texto: "Subir otro comprobante", url: panelPagos() }),
`${programa.concepto}: comprobante del ${formatFechaCorta(pago.fecha)} rechazado. ${motivo || ""}`.trim(),
{
titulo: "Comprobante rechazado",
@@ -340,11 +346,11 @@ function mensajeRecordatorio(
.slice(0, 5)
.map((p) => `${formatFechaCorta(p.fecha)} ${p.programa.concepto} ${formatoMoneda(p.monto, p.programa.moneda)}`)
.join("; ") +
`. Sube tu comprobante en ${PANEL_PAGOS}`;
`. Sube tu comprobante en ${panelPagos()}`;
return {
titulo,
html: plantilla(titulo, cuerpo, { texto: "Subir comprobante", url: PANEL_PAGOS }),
html: plantilla(titulo, cuerpo, { texto: "Subir comprobante", url: panelPagos() }),
texto,
push: {
titulo: n === 1 ? "Tienes un pago pendiente" : `Tienes ${n} pagos pendientes`,