From 4283250eace07f6e70cb4054a93b6384497812f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= <35082514+alezmad@users.noreply.github.com> Date: Tue, 24 Feb 2026 23:30:35 +0000 Subject: [PATCH] fix: proxy subscribe through Next.js API route to avoid network permission prompt Browser was requesting local network access for the Tailscale URL. Now both forms POST to /api/subscribe which proxies server-side to the leads-api container. Co-Authored-By: Claude Opus 4.6 --- site/app/api/subscribe/route.ts | 18 ++++++++++++++++++ site/app/newsletter-form.tsx | 4 +--- site/app/subscribe-modal.tsx | 4 +--- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 site/app/api/subscribe/route.ts diff --git a/site/app/api/subscribe/route.ts b/site/app/api/subscribe/route.ts new file mode 100644 index 0000000..401bd02 --- /dev/null +++ b/site/app/api/subscribe/route.ts @@ -0,0 +1,18 @@ +import { NextRequest, NextResponse } from "next/server"; + +const API_URL = process.env.LEADS_API_URL || "http://leads-api:3400"; + +export async function POST(req: NextRequest) { + try { + const body = await req.json(); + const res = await fetch(`${API_URL}/subscribe`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + }); + const data = await res.json(); + return NextResponse.json(data, { status: res.status }); + } catch { + return NextResponse.json({ error: "upstream error" }, { status: 502 }); + } +} diff --git a/site/app/newsletter-form.tsx b/site/app/newsletter-form.tsx index b5e39f1..e835d26 100644 --- a/site/app/newsletter-form.tsx +++ b/site/app/newsletter-form.tsx @@ -2,8 +2,6 @@ import { useState } from "react"; -const API_URL = "https://alezmad-nuc.tail58f5ad.ts.net"; - export function NewsletterForm({ project = "cladm" }: { project?: string }) { const [email, setEmail] = useState(""); const [status, setStatus] = useState<"idle" | "loading" | "ok" | "error">("idle"); @@ -14,7 +12,7 @@ export function NewsletterForm({ project = "cladm" }: { project?: string }) { if (!email.trim()) return; setStatus("loading"); try { - const res = await fetch(`${API_URL}/subscribe`, { + const res = await fetch("/api/subscribe", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: email.trim(), project }), diff --git a/site/app/subscribe-modal.tsx b/site/app/subscribe-modal.tsx index 79c0537..923b493 100644 --- a/site/app/subscribe-modal.tsx +++ b/site/app/subscribe-modal.tsx @@ -2,8 +2,6 @@ import { useState, useEffect, useRef, useCallback } from "react"; -const API_URL = "https://alezmad-nuc.tail58f5ad.ts.net"; - type Phase = "boot" | "prompt" | "sending" | "done"; const BOOT_LINES = [ @@ -86,7 +84,7 @@ export function SubscribeModal() { setPhase("sending"); setError(""); try { - const res = await fetch(`${API_URL}/subscribe`, { + const res = await fetch("/api/subscribe", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: email.trim(), project: "cladm" }),