This project uses GitHub Actions to deploy the frontend to GitHub Pages and the backend to AWS EC2.
The frontend is automatically deployed to GitHub Pages when changes are pushed to the main branch in the client/ directory.
- Go to your repository settings
- Navigate to "Pages" section
- Set source to "GitHub Actions"
- The deployment will be handled automatically by the workflow
The backend is deployed to an AWS EC2 instance when changes are pushed to the main branch in the server/ directory.
Add these secrets to your GitHub repository (Settings > Secrets and variables > Actions):
EC2_HOST: Your EC2 instance public IP or domain nameEC2_USERNAME: SSH username (usuallyubuntufor Ubuntu instances)EC2_SSH_KEY: Your private SSH key for EC2 accessEC2_PORT: SSH port (default: 22)
-
Launch an EC2 instance (Ubuntu 24.04 recommended)
-
Configure security groups to allow:
- SSH (port 22) from your IP
- HTTP (port 80) from anywhere
- HTTPS (port 443) from anywhere
- Custom port 3001 for your backend API
-
Install Node.js on the EC2 instance (Ubuntu 24.04):
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs node --version # Should show v22.x.x
-
Create deployment directory:
mkdir -p /home/ubuntu/maizebus-backend
-
Create environment file:
sudo nano /home/ubuntu/maizebus-backend/.env
Add your environment variables:
EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USER=your-email@gmail.com EMAIL_PASS=your-app-password EMAIL_TO=contact@maizebus.com PORT=3001 NODE_ENV=production FRONTEND_URL=https://mbusdev.github.io
-
Set up reverse proxy (optional, for custom domain):
sudo apt update sudo apt install nginx sudo nano /etc/nginx/sites-available/maizebus
Add this configuration:
server { listen 80; server_name your-domain.com; location / { proxy_pass http://localhost:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; } }
Enable the site:
sudo ln -s /etc/nginx/sites-available/maizebus /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
Frontend (GitHub Pages) → Backend (EC2)
- Frontend URL:
https://mbusdev.github.io - Backend URL:
https://your-ec2-domain.comorhttp://your-ec2-ip:3001 - CORS is configured to allow GitHub Pages root domain
- Backend binds to
0.0.0.0:3001for external access
Security Group Requirements:
- Port 22 (SSH): Your IP only
- Port 80 (HTTP): 0.0.0.0/0 (for reverse proxy)
- Port 443 (HTTPS): 0.0.0.0/0 (for reverse proxy)
- Port 3001 (API): 0.0.0.0/0 (for direct API access)
Testing Connectivity:
# Test backend health endpoint
curl http://your-ec2-ip:3001/health
# Test API endpoint
curl -X POST http://your-ec2-ip:3001/api/contact \
-H "Content-Type: application/json" \
-d '{"name":"Test","email":"test@test.com","inquiryType":"general","subject":"Test","message":"Test"}'The GitHub Actions workflow will:
- Build the backend and API
- Create a deployment package
- Upload to EC2 via SSH
- Extract and install dependencies
- Set up systemd service
- Start the backend service
- Clean up old deployments
To deploy manually:
# Build locally
cd server && npm run build
# Create deployment package
tar -czf deployment.tar.gz -C server/dist .
# Upload to EC2
scp -i your-key.pem deployment.tar.gz ubuntu@your-ec2-ip:/home/ubuntu/maizebus-backend/current/
# SSH into EC2 and extract
ssh -i your-key.pem ubuntu@your-ec2-ip
cd /home/ubuntu/maizebus-backend/current
tar -xzf deployment.tar.gz
npm ci --production
sudo systemctl restart maizebus-backendCheck service status:
sudo systemctl status maizebus-backend
sudo journalctl -u maizebus-backend -f- Service won't start: Check logs with
sudo journalctl -u maizebus-backend - Port not accessible: Verify security group settings
- Environment variables: Ensure
.envfile exists and has correct values - Permissions: Check file ownership with
ls -la /home/ubuntu/maizebus-backend/
VITE_API_URL: Backend API URL (set in GitHub Pages environment)
EMAIL_HOST: SMTP server hostnameEMAIL_PORT: SMTP server portEMAIL_USER: SMTP usernameEMAIL_PASS: SMTP password/app passwordEMAIL_TO: Recipient email addressPORT: Server port (default: 3001)NODE_ENV: Environment (production)FRONTEND_URL: Frontend URL for CORS