Fastify (Node.js)
const fastify = require('fastify')({ logger: true })
async function isDisposable(email) {
try {
const r = await fetch(
`https://api.disposableguard.com/v1/check?email=${encodeURIComponent(email)}`,
{ headers: { Authorization: `Bearer ${process.env.DG_KEY}` } }
)
if (!r.ok) return false
const data = await r.json()
return data.is_disposable === true
} catch {
return false
}
}
fastify.post('/signup', async (request, reply) => {
const { email, password } = request.body
if (await isDisposable(email)) {
return reply.code(400).send({ error: 'Please use a real email address.' })
}
// ...signup logic
return { ok: true }
})
fastify.listen({ port: 3000 })Notes
Requires Node 18+ for native fetch. Install with `npm i fastify`.