3. Create the Handler
Deploy this as a serverless function or Node.js endpoint. It forwards the submission
to Peach Form and then inserts it into your database.
// handler.js — deploy to Vercel, Netlify, or any Node.js server
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).end("Method not allowed");
}
const body = req.body; // parsed JSON
// 1. Forward submission to Peach Form
const pfRes = await fetch("https://api.peachform.com/f/YOUR_FORM_ID", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!pfRes.ok) {
return res.status(502).json({ error: "Peach Form submission failed" });
}
// 2. Store submission in your own database
await pool.query(
"INSERT INTO form_submissions (data) VALUES ($1)",
[JSON.stringify(body)],
);
return res.status(200).json({ success: true });
}