chore: Add free tools on marketing pages

This commit is contained in:
Dries Augustyns
2025-12-29 19:22:35 +01:00
parent 5993b842a0
commit 6293259225
15 changed files with 1822 additions and 22 deletions
@@ -0,0 +1,70 @@
import type {NextApiRequest, NextApiResponse} from 'next';
import {UtilitySchemas} from '@plunk/shared';
import {API_URI} from '../../lib/constants';
interface VerifyEmailResponse {
email: string;
valid: boolean;
isDisposable: boolean;
isTypo: boolean;
isPlusAddressed: boolean;
domainExists: boolean;
hasMxRecords: boolean;
suggestedEmail?: string;
reasons: string[];
}
interface ErrorResponse {
error: string;
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<VerifyEmailResponse | ErrorResponse>,
) {
// Only allow POST requests
if (req.method !== 'POST') {
return res.status(405).json({error: 'Method not allowed'});
}
// Validate input using Zod schema
const result = UtilitySchemas.email.safeParse(req.body);
if (!result.success) {
return res.status(400).json({error: 'Invalid email format'});
}
const {email} = result.data;
// Get secret key from environment
const secretKey = process.env.PLUNK_SECRET_KEY;
if (!secretKey) {
console.error('PLUNK_SECRET_KEY is not configured');
return res.status(500).json({error: 'Service configuration error'});
}
try {
// Call internal Plunk API with secret key from env
const response = await fetch(`${API_URI}/v1/verify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${secretKey}`,
},
body: JSON.stringify({email}),
});
const data = await response.json();
if (!response.ok) {
console.error('Plunk API error:', data);
return res.status(response.status).json({error: data.error?.message || 'Verification failed'});
}
// Return the data field from the Plunk API response
return res.status(200).json(data.data);
} catch (error) {
console.error('Error verifying email:', error);
return res.status(500).json({error: 'Internal server error'});
}
}