import express from 'express' import nodemailer from 'nodemailer' import path from 'path' import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const app = express() app.use(express.json()) // Serve static files from Vite build app.use(express.static(path.join(__dirname, 'dist'))) // Contact API endpoint app.post('/api/contact', async (req, res) => { const { name, organisation, email, subject, message } = req.body if (!name || !email || !subject || !message) { return res.status(400).json({ success: false, message: 'All fields are required' }) } const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ if (!emailRegex.test(email)) { return res.status(400).json({ success: false, message: 'Invalid email address' }) } const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST, port: Number(process.env.SMTP_PORT), secure: true, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS, }, }) const contactEmail = process.env.CONTACT_EMAIL || 'andy@charlwood.xyz' try { // Admin notification await transporter.sendMail({ from: `"${name}" <${process.env.SMTP_USER}>`, replyTo: email, to: contactEmail, subject: `Portfolio Referral: ${subject}`, html: `
Referring Clinician: ${name}
Organisation: ${organisation || 'Not specified'}
Email: ${email}
Subject: ${subject}
${message}
This message was sent from your portfolio contact form.
I've received your referral and will get back to you as soon as possible.
Your message:
${message}
Best regards,
Andy Charlwood
Informatics Pharmacist · NHS Norfolk & Waveney ICB
This is an automated confirmation. Please do not reply to this email.