Spaces:
Sleeping
Sleeping
Upload pages/api/contact.js with huggingface_hub
Browse files- pages/api/contact.js +49 -0
pages/api/contact.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default async function handler(req, res) {
|
| 2 |
+
if (req.method !== 'POST') {
|
| 3 |
+
return res.status(405).json({ message: 'Method not allowed' });
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
const { name, email, company, message } = req.body;
|
| 7 |
+
|
| 8 |
+
// Basic validation
|
| 9 |
+
if (!name || !email || !message) {
|
| 10 |
+
return res.status(400).json({ message: 'Missing required fields' });
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
// Email validation
|
| 14 |
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
| 15 |
+
if (!emailRegex.test(email)) {
|
| 16 |
+
return res.status(400).json({ message: 'Invalid email format' });
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
try {
|
| 20 |
+
// Here you would typically integrate with:
|
| 21 |
+
// - Email service (SendGrid, AWS SES)
|
| 22 |
+
// - CRM system (Salesforce, HubSpot)
|
| 23 |
+
// - Slack/Discord for notifications
|
| 24 |
+
// - Database to store leads
|
| 25 |
+
|
| 26 |
+
console.log('Contact form submission:', {
|
| 27 |
+
name,
|
| 28 |
+
email,
|
| 29 |
+
company,
|
| 30 |
+
message,
|
| 31 |
+
timestamp: new Date().toISOString()
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
// Simulate processing delay
|
| 35 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 36 |
+
|
| 37 |
+
// In production, implement actual email/CRM integration here
|
| 38 |
+
// For now, we'll just return success
|
| 39 |
+
|
| 40 |
+
return res.status(200).json({
|
| 41 |
+
message: 'Contact form submitted successfully',
|
| 42 |
+
// In production, remove this data from response
|
| 43 |
+
data: { name, email, company, message }
|
| 44 |
+
});
|
| 45 |
+
} catch (error) {
|
| 46 |
+
console.error('Contact form error:', error);
|
| 47 |
+
return res.status(500).json({ message: 'Internal server error' });
|
| 48 |
+
}
|
| 49 |
+
}
|