2.0 KiB
2.0 KiB
Backend Setup Guide
This guide explains how to set up the backend for the contact form functionality.
Overview
The contact form uses a Node.js/Express backend with Nodemailer to send emails via Gmail SMTP. During development, Vite proxies API requests to the Node.js server.
Setup Instructions
1. Install Dependencies
Make sure all dependencies are installed:
npm install
# or
bun install
2. Configure Gmail SMTP
To send emails via Gmail:
- Enable 2-factor authentication on your Gmail account
- Generate an App Password:
- Go to your Google Account settings
- Navigate to Security > 2-Step Verification > App passwords
- Generate a new app password for "Mail"
- Update the credentials in
.envfile:EMAIL_USER=scandrone308@gmail.com EMAIL_PASS=your-app-password
3. Run the Application
You'll need to run both the frontend development server and the backend server:
Terminal 1 (Frontend):
npm run dev
# or
bun run dev
Terminal 2 (Backend):
npm start
# or
bun run start
4. Production Deployment
For production deployment:
-
Build the frontend:
npm run build # or bun run build -
Run the server which will serve both the API and the built frontend:
npm start # or bun run start
How It Works
- The React frontend sends form data to
/api/contactvia fetch - Vite proxies
/apirequests to the Node.js server (during development) - The Node.js server receives the data and sends an email using Nodemailer
- The email is sent to bayan10kh@gmail.com via Gmail SMTP
Troubleshooting
If emails aren't being sent:
- Check that your Gmail credentials are correct in the
.envfile - Verify that you're using an App Password, not your regular Gmail password
- Ensure 2-factor authentication is enabled on your Gmail account
- Check the server console for error messages
- Verify that your hosting provider allows SMTP connections
- Make sure the EMAIL_USER and EMAIL_PASS variables are properly set in the
.envfile