Loading page
One route, express.json(), a minimum of validation, and an upstream POST.
import express from "express";
const app = express();
app.use(express.json({ limit: "32kb" }));
app.post("/contact", async (request, response) => {
const { email, message } = request.body ?? {};
if (typeof email !== "string" || typeof message !== "string") {
return response.status(400).json({ error: "Missing fields" });
}
const upstream = await fetch("https://formivo.faizyab.me/api/f/YOUR_FORM_ID", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ email, message }),
signal: AbortSignal.timeout(10_000),
}).catch(() => null);
if (!upstream?.ok) {
return response.status(502).json({ error: "Could not send" });
}
return response.status(201).json({ ok: true });
});Your route returns 201; the upstream result is what you check.
| Symptom | Fix |
|---|---|
| request.body is undefined | express.json() must run before the route. |
| Large payload errors | Keep the JSON limit at 32kb and validate field lengths. |