Astro
// src/pages/api/signup.ts
import type { APIRoute } from 'astro';
export const POST: APIRoute = async ({ request }) => {
const { email } = await request.json();
try {
const r = await fetch(
`https://api.disposableguard.com/v1/check?email=${encodeURIComponent(email)}`,
{ headers: { Authorization: `Bearer ${import.meta.env.DG_KEY}` } }
);
if (r.ok) {
const data = await r.json();
if (data.is_disposable) {
return new Response(
JSON.stringify({ error: 'Please use a real email address.' }),
{ status: 400 }
);
}
}
} catch {
// fail-open
}
// ...signup logic
return new Response(JSON.stringify({ ok: true }));
};Notes
Add `DG_KEY` to `.env`. Astro endpoint runs on the server.