Skip to content

Commit ca0c073

Browse files
committed
feat(deployment): implement automated deployment scripts and enhance backend setup verification; add CORS fallback mechanism for form submissions
1 parent 2289deb commit ca0c073

File tree

10 files changed

+858
-51
lines changed

10 files changed

+858
-51
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Deploy Backend to Google Apps Script
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths: ['backend/**']
7+
workflow_dispatch:
8+
inputs:
9+
deploy_description:
10+
description: 'Deployment description'
11+
required: false
12+
default: 'Automated deployment from GitHub Actions'
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
18+
defaults:
19+
run:
20+
working-directory: ./backend
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '18'
30+
cache: 'npm'
31+
cache-dependency-path: backend/package-lock.json
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Install Google Apps Script CLI
37+
run: npm install -g @google/clasp
38+
39+
- name: Create .clasprc.json
40+
run: |
41+
echo '${{ secrets.CLASPRC_JSON }}' > ~/.clasprc.json
42+
43+
- name: Setup environment variables
44+
run: |
45+
echo "CLASP_SCRIPT_ID=${{ secrets.CLASP_SCRIPT_ID }}" > .env
46+
echo "DEPLOYMENT_DESCRIPTION=${{ github.event.inputs.deploy_description || 'Automated deployment from GitHub Actions' }}" >> .env
47+
echo "DEPLOYMENT_VERSION_DESCRIPTION=Deploy from commit ${{ github.sha }}" >> .env
48+
49+
- name: Validate environment
50+
run: |
51+
if [ -z "${{ secrets.CLASP_SCRIPT_ID }}" ]; then
52+
echo "Error: CLASP_SCRIPT_ID secret is not set"
53+
exit 1
54+
fi
55+
if [ -z "${{ secrets.CLASPRC_JSON }}" ]; then
56+
echo "Error: CLASPRC_JSON secret is not set"
57+
exit 1
58+
fi
59+
60+
- name: Deploy to Google Apps Script
61+
run: |
62+
# Update .clasp.json with script ID
63+
cat > .clasp.json << EOF
64+
{
65+
"scriptId": "${{ secrets.CLASP_SCRIPT_ID }}",
66+
"rootDir": "",
67+
"scriptExtensions": [".js", ".gs"],
68+
"htmlExtensions": [".html"],
69+
"jsonExtensions": [".json"],
70+
"filePushOrder": [],
71+
"skipSubdirectories": false
72+
}
73+
EOF
74+
75+
# Push code
76+
clasp push --force
77+
78+
# Deploy
79+
clasp deploy --description "${{ github.event.inputs.deploy_description || 'Automated deployment from GitHub Actions' }}"
80+
81+
- name: Clean up credentials
82+
if: always()
83+
run: |
84+
rm -f ~/.clasprc.json
85+
rm -f .env
86+
rm -f .clasp.json

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,48 @@ Google Apps Script execution logs via `cd backend && npm run logs` and Google Cl
423423

424424
---
425425

426+
## 🔧 Recent Improvements
427+
428+
### 📡 **CORS & Form Submission Fixes**
429+
430+
Recently resolved CORS issues with Google Apps Script backend that were preventing form submissions:
431+
432+
**Problem**: Contact forms and job applications were failing with CORS errors when submitting from localhost and production environments.
433+
434+
**Solution Implemented**:
435+
-**Automatic Fallback Mechanism**: Forms now automatically retry with GET requests if POST fails due to CORS
436+
-**Enhanced Error Handling**: Better user feedback and error recovery
437+
-**Cross-Origin Compatibility**: Works from any domain (localhost, production, etc.)
438+
-**Robust Backend**: Updated Google Apps Script to handle both POST and GET submissions
439+
440+
**Files Enhanced**:
441+
- `frontend/src/utils/api.ts` - Added fallback submission logic
442+
- `backend/thinkREDBot.js` - Enhanced CORS handling and GET request support
443+
444+
### 🚀 **Secure Deployment Pipeline**
445+
446+
Implemented comprehensive deployment automation:
447+
448+
**Backend Deployment**:
449+
-**Multiple Deployment Methods**: Node.js script, Bash script, GitHub Actions
450+
-**Environment Management**: Secure configuration via `.env` files
451+
-**Automated CI/CD**: GitHub Actions workflow for hands-free deployment
452+
-**Security First**: No hardcoded credentials, proper secret management
453+
454+
**Quick Backend Deployment**:
455+
```bash
456+
cd backend
457+
npm run setup # First time only
458+
npm run deploy # Deploy to Google Apps Script
459+
```
460+
461+
**Frontend Deployment**:
462+
-**GitHub Pages**: Automatic deployment via GitHub Actions
463+
-**Hostinger**: Production deployment with custom domain
464+
-**Build Optimization**: Efficient bundling and asset optimization
465+
466+
---
467+
426468
## 🤝 Contributing
427469

428470
### 🚀 **Getting Started**

backend/.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Backend Environment Variables
2+
# Copy this file to .env and fill in your values
3+
4+
# Google Apps Script Configuration
5+
CLASP_SCRIPT_ID=1lxhn-Siz6ThM7rWHveiEVE1HlyA7fimu4LMifyFLXbaXRmEbT5lVL78J
6+
7+
# Deployment Configuration
8+
DEPLOYMENT_DESCRIPTION=Automated deployment from local development
9+
DEPLOYMENT_VERSION_DESCRIPTION=Contact form and job application backend
10+
11+
# Security
12+
# Ensure this file is in .gitignore to keep credentials secure

backend/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Environment variables (contains sensitive information)
2+
.env
3+
4+
# Clasp credentials
5+
.clasprc.json
6+
7+
# Node modules
8+
node_modules/
9+
10+
# Logs
11+
*.log
12+
npm-debug.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage/
21+
22+
# Dependency directories
23+
jspm_packages/
24+
25+
# Optional npm cache directory
26+
.npm
27+
28+
# Optional REPL history
29+
.node_repl_history
30+
31+
# Output of 'npm pack'
32+
*.tgz
33+
34+
# Yarn Integrity file
35+
.yarn-integrity
36+
37+
# MacOS
38+
.DS_Store
39+
40+
# Windows
41+
Thumbs.db
42+
ehthumbs.db
43+
Desktop.ini

0 commit comments

Comments
 (0)