feat: configure n8n webhooks and update related documentation #2
@@ -66,6 +66,7 @@ FILE_SIZE_LIMIT=52428800
|
||||
N8N_ENCRYPTION_KEY=mc-cars-n8n-encryption-key-change-me
|
||||
N8N_USER_EMAIL=admin@mccars.local
|
||||
N8N_USER_PASSWORD=McCars-N8n-Admin1
|
||||
N8N_WEBHOOK_URL=http://localhost:55521/webhook/manual-email-send
|
||||
N8N_POSTGRES_CREDENTIAL_ID=AWozEaiOSymMj7JF
|
||||
N8N_POSTGRES_CREDENTIAL_NAME=Postgres account
|
||||
N8N_SMTP_CREDENTIAL_ID=nRMemi1sz2C0N4Vu
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
# Production Deployment - n8n Webhook Routing
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Ensure your production environment has:
|
||||
- `docker-compose.yml` and `docker-compose.local.yml` updated with new n8n webhook routing
|
||||
- `supabase/kong.yml` updated with n8n webhook service
|
||||
- `frontend/admin.js` updated with new sendOrderEmailDirect function
|
||||
- Production domain configured (e.g., `your-domain.com`)
|
||||
|
||||
## Deployment Steps
|
||||
|
||||
### 1. Update Production Config
|
||||
|
||||
Edit `frontend/config.js` and replace `localhost:55521` with your production domain:
|
||||
|
||||
```javascript
|
||||
window.MCCARS_CONFIG={
|
||||
SUPABASE_URL:"https://your-domain.com",
|
||||
SUPABASE_ANON_KEY:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||
N8N_WEBHOOK_URL:"https://your-domain.com/webhook/manual-email-send"
|
||||
};
|
||||
```
|
||||
|
||||
Replace:
|
||||
- `your-domain.com` with your actual production domain
|
||||
- Keep the same ANON_KEY value
|
||||
|
||||
### 2. Optional: Configure WEBHOOK_DOMAIN
|
||||
|
||||
If you want n8n to know its public webhook URL (for n8n UI display), set environment variable:
|
||||
|
||||
```bash
|
||||
export WEBHOOK_DOMAIN=https://your-domain.com
|
||||
```
|
||||
|
||||
This tells n8n that webhooks are accessible at `https://your-domain.com/webhook/*` from the internet.
|
||||
|
||||
### 3. Deploy Updated Files
|
||||
|
||||
Push these files to production:
|
||||
- `supabase/kong.yml` (updated with n8n webhook service)
|
||||
- `docker-compose.yml` (updated WEBHOOK_URL variable syntax)
|
||||
- `frontend/config.js` (updated with production domain)
|
||||
- `frontend/admin.js` (updated sendOrderEmailDirect function)
|
||||
|
||||
### 4. Restart Stack on Production Server
|
||||
|
||||
```bash
|
||||
# On production host
|
||||
cd /mnt/user/appdata/mc-cars # or your deployment path
|
||||
|
||||
# Pull latest code
|
||||
git pull origin dev # or your deployment branch
|
||||
|
||||
# Restart with new config
|
||||
docker-compose down
|
||||
docker-compose up -d --build
|
||||
|
||||
# Verify services are healthy
|
||||
docker-compose ps
|
||||
```
|
||||
|
||||
### 5. Verify Webhook Routing
|
||||
|
||||
Test webhook from production domain:
|
||||
|
||||
```bash
|
||||
curl 'https://your-domain.com/webhook/manual-email-send' \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
-d 'sales_order_id=YOUR_ORDER_ID'
|
||||
```
|
||||
|
||||
Expected response: 200 OK with n8n workflow result
|
||||
|
||||
## Network Setup
|
||||
|
||||
Kong must be accessible from the internet:
|
||||
- **Port 55521** exposed via reverse proxy (nginx/Apache) or firewall rule
|
||||
- Domain DNS points to production server
|
||||
- SSL certificate configured (recommended to use Kong's 8443 port with cert)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "Failed to fetch" on send email button
|
||||
|
||||
1. Check Kong is routing webhook:
|
||||
```bash
|
||||
docker-compose exec kong curl -v http://n8n:5678/webhook/manual-email-send
|
||||
```
|
||||
|
||||
2. Verify Kong config loaded:
|
||||
```bash
|
||||
docker-compose logs kong | grep "n8n-webhooks"
|
||||
```
|
||||
|
||||
3. Check n8n workflow is active:
|
||||
```bash
|
||||
docker-compose logs n8n | grep "webhook"
|
||||
```
|
||||
|
||||
### CORS errors
|
||||
|
||||
Ensure Kong's CORS plugin is enabled for `/webhook/` routes (should be in kong.yml):
|
||||
|
||||
```yaml
|
||||
plugins:
|
||||
- name: cors
|
||||
```
|
||||
|
||||
### Webhook not triggering from browser
|
||||
|
||||
Verify in browser DevTools:
|
||||
1. Network tab shows POST to `/webhook/manual-email-send`
|
||||
2. Response status is 200 (not 404 or 500)
|
||||
3. Check n8n logs for workflow execution
|
||||
|
||||
## Rollback
|
||||
|
||||
If issues occur:
|
||||
|
||||
```bash
|
||||
# Rollback config.js to localhost for debugging
|
||||
git checkout frontend/config.js
|
||||
docker-compose up -d
|
||||
|
||||
# Then fix and redeploy
|
||||
```
|
||||
|
||||
## Verification Checklist
|
||||
|
||||
- [ ] Kong routing `/webhook/*` to n8n ✓
|
||||
- [ ] Frontend config.js has production domain ✓
|
||||
- [ ] Admin portal can reach Kong on correct port ✓
|
||||
- [ ] Webhook accepts POST requests ✓
|
||||
- [ ] n8n workflow triggers and sends email ✓
|
||||
- [ ] Email appears in order record ✓
|
||||
@@ -121,31 +121,51 @@ The admin is seeded with `must_change_password = true` in `raw_user_meta_data`.
|
||||
- RPCs: `calculate_price(uuid, date, date)` (public pricing), `create_lead(...)` (server-side submission), `qualify_lead(uuid, text)`, `disqualify_lead(uuid, text)`, `reopen_lead(uuid)` — transactional, `SECURITY INVOKER`, `authenticated` only (except calculate_price and create_lead which are anon-accessible).
|
||||
- Realtime: `supabase_realtime` publication broadcasts inserts/updates on leads, customers, vehicles.
|
||||
|
||||
## Environment: two variables per deployment
|
||||
## Environment: three variables per deployment
|
||||
|
||||
Only two lines in `.env` need changing between environments:
|
||||
Three variables in `.env` need changing between environments:
|
||||
|
||||
| Variable | Local dev | Production |
|
||||
|---|---|---|
|
||||
| `SITE_URL` | `http://localhost:55580` | `https://your.domain.com` |
|
||||
| `SUPABASE_PUBLIC_URL` | `http://localhost:55521` | `https://your.domain.com` |
|
||||
| `N8N_WEBHOOK_URL` | `http://localhost:55521/webhook/manual-email-send` | `https://your.domain.com/webhook/manual-email-send` |
|
||||
|
||||
All other GoTrue URLs (`API_EXTERNAL_URL`, `GOTRUE_SITE_URL`, `GOTRUE_URI_ALLOW_LIST`) are derived automatically in `docker-compose.yml`.
|
||||
|
||||
On the NAS (example):
|
||||
### Quick setup with deploy-setup.sh
|
||||
|
||||
Use the included deployment script to update all environment variables at once:
|
||||
|
||||
```bash
|
||||
sed -i 's|SITE_URL=.*|SITE_URL=https://your.domain.com|' .env
|
||||
sed -i 's|SUPABASE_PUBLIC_URL=.*|SUPABASE_PUBLIC_URL=https://your.domain.com|' .env
|
||||
docker compose up -d --force-recreate web
|
||||
./deploy-setup.sh https://www.mc-cars.at
|
||||
```
|
||||
|
||||
For mc-cars.at:
|
||||
This updates `.env` and outputs the configuration. Then restart:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
### Manual setup (legacy sed method)
|
||||
|
||||
```bash
|
||||
sed -i 's|SITE_URL=.*|SITE_URL=https://www.mc-cars.at|' .env
|
||||
sed -i 's|SUPABASE_PUBLIC_URL=.*|SUPABASE_PUBLIC_URL=https://www.mc-cars.at|' .env
|
||||
docker compose up -d --force-recreate web
|
||||
sed -i 's|N8N_WEBHOOK_URL=.*|N8N_WEBHOOK_URL=https://www.mc-cars.at/webhook/manual-email-send|' .env
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
### How n8n webhooks work
|
||||
|
||||
- n8n runs internally (not exposed to the internet)
|
||||
- Kong API gateway proxies `/webhook/*` traffic to internal n8n
|
||||
- Browser requests to `https://your.domain.com/webhook/manual-email-send` route through Kong → n8n
|
||||
- Frontend config is generated at container startup from `N8N_WEBHOOK_URL` environment variable
|
||||
|
||||
See [N8N_WEBHOOK_ROUTING.md](N8N_WEBHOOK_ROUTING.md) for full architecture details.
|
||||
|
||||
## Deployment & portability
|
||||
|
||||
Runtime state under `/mnt/user/appdata/mc-cars/data/`:
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# MC Cars Deployment Configuration Setup
|
||||
# Usage: ./deploy-setup.sh https://www.mc-cars.at
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: ./deploy-setup.sh <domain>"
|
||||
echo "Example: ./deploy-setup.sh https://www.mc-cars.at"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DOMAIN="$1"
|
||||
|
||||
echo "🚀 Configuring MC Cars for: $DOMAIN"
|
||||
|
||||
# Update environment variables
|
||||
sed -i "s|SITE_URL=.*|SITE_URL=$DOMAIN|" .env
|
||||
sed -i "s|SUPABASE_PUBLIC_URL=.*|SUPABASE_PUBLIC_URL=$DOMAIN|" .env
|
||||
sed -i "s|N8N_WEBHOOK_URL=.*|N8N_WEBHOOK_URL=$DOMAIN/webhook/manual-email-send|" .env
|
||||
|
||||
echo "✅ Updated .env:"
|
||||
echo " SITE_URL=$DOMAIN"
|
||||
echo " SUPABASE_PUBLIC_URL=$DOMAIN"
|
||||
echo " N8N_WEBHOOK_URL=$DOMAIN/webhook/manual-email-send"
|
||||
|
||||
echo ""
|
||||
echo "📋 Next steps:"
|
||||
echo " 1. Verify .env looks correct: grep -E 'SITE_URL|SUPABASE_PUBLIC_URL|N8N_WEBHOOK_URL' .env"
|
||||
echo " 2. Restart services: docker-compose down && docker-compose up -d --build"
|
||||
echo " 3. Test webhook: curl '$DOMAIN/webhook/manual-email-send' -d 'sales_order_id=test'"
|
||||
+1
-1
@@ -10,7 +10,7 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
# (anon key only — safe for the browser).
|
||||
RUN rm -f /usr/share/nginx/html/Dockerfile /usr/share/nginx/html/nginx.conf
|
||||
|
||||
RUN printf '#!/bin/sh\nset -eu\ncat > /usr/share/nginx/html/config.js <<EOF\nwindow.MCCARS_CONFIG = {\n SUPABASE_URL: "${SUPABASE_URL:-http://localhost:8000}",\n SUPABASE_ANON_KEY: "${SUPABASE_ANON_KEY:-}"\n};\nEOF\nexec nginx -g "daemon off;"\n' > /docker-entrypoint.d/99-config.sh \
|
||||
RUN printf '#!/bin/sh\nset -eu\ncat > /usr/share/nginx/html/config.js <<EOF\nwindow.MCCARS_CONFIG = {\n SUPABASE_URL: "${SUPABASE_URL:-http://localhost:8000}",\n SUPABASE_ANON_KEY: "${SUPABASE_ANON_KEY:-}",\n N8N_WEBHOOK_URL: "${N8N_WEBHOOK_URL:-http://localhost:55521/webhook/manual-email-send}"\n};\nEOF\nexec nginx -g "daemon off;"\n' > /docker-entrypoint.d/99-config.sh \
|
||||
&& chmod +x /docker-entrypoint.d/99-config.sh
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
Reference in New Issue
Block a user