// Application form API endpoint // Handles full event applications with PostgreSQL storage and Resend emails const { Pool } = require('pg'); const { Resend } = require('resend'); // Initialize PostgreSQL connection pool const pool = new Pool({ connectionString: process.env.DATABASE_URL, ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false }); // Initialize Resend const resend = new Resend(process.env.RESEND_API_KEY); // Email templates const confirmationEmail = (application) => ({ subject: 'Application Received - Valley of the Commons', html: `
Dear ${application.first_name},
We've received your application to join Valley of the Commons (August 24 - September 20, 2026).
In the meantime, feel free to explore more about the Commons Hub and our community:
If you have any questions, reply to this email and we'll get back to you.
With warmth,
The Valley of the Commons Team
Application ID: ${application.id}
Submitted: ${new Date(application.submitted_at).toLocaleDateString('en-US', { dateStyle: 'long' })}
| Name: | ${application.first_name} ${application.last_name} |
| Email: | ${application.email} |
| Location: | ${application.city || ''}, ${application.country || ''} |
| Attendance: | ${application.attendance_type === 'full' ? 'Full 4 weeks' : 'Partial'} |
| Scholarship: | ${application.scholarship_needed ? 'Yes' : 'No'} |
${application.motivation}
Application ID: ${application.id}