feat: add production configuration with environment variables
- Add .env file for production deployment with reverse proxy - Add docker-compose.prod.yml for production profile - Add docker-compose.override.yml for local development - Update docker-compose.yml with all configurable variables - Update frontend to use VITE_* environment variables - Update backend to support CORS_ORIGINS and WEBHOOK_BASE_URL - Add vite.config.ts allowedHosts for reverse proxy - Add documentation for docker-compose and reverse proxy setup All URLs are now configurable via environment variables: - VITE_API_URL: Backend API endpoint - VITE_WEBHOOK_BASE_URL: Webhook base URL - VITE_INSTALL_SCRIPT_URL: Install script URL - VITE_APP_URL: Frontend URL - CORS_ORIGINS: Allowed CORS origins - WEBHOOK_BASE_URL: Backend webhook base URL
This commit is contained in:
131
docs/docker-compose.md
Normal file
131
docs/docker-compose.md
Normal file
@@ -0,0 +1,131 @@
|
||||
# Docker Compose Configuration
|
||||
|
||||
Questa directory contiene diverse configurazioni Docker Compose per vari ambienti.
|
||||
|
||||
## File Disponibili
|
||||
|
||||
| File | Scopo | Uso |
|
||||
|------|-------|-----|
|
||||
| `docker-compose.yml` | Configurazione base con variabili d'ambiente | Sviluppo e produzione |
|
||||
| `docker-compose.override.yml` | Override per sviluppo locale | Caricato automaticamente |
|
||||
| `docker-compose.prod.yml` | Configurazione produzione | Da usare con `-f` |
|
||||
|
||||
## Variabili d'Ambiente
|
||||
|
||||
Tutte le variabili sono configurabili tramite file `.env` o variabili di sistema.
|
||||
|
||||
### Frontend (VITE_*)
|
||||
|
||||
| Variabile | Default | Descrizione |
|
||||
|-----------|---------|-------------|
|
||||
| `VITE_API_URL` | `http://fake-backend:3000` | URL del backend API |
|
||||
| `VITE_WEBHOOK_BASE_URL` | `http://localhost:3001/webhook` | Base URL webhook |
|
||||
| `VITE_INSTALL_SCRIPT_URL` | `http://localhost:3001/install.sh` | URL script installazione |
|
||||
| `VITE_APP_NAME` | `LogWhispererAI` | Nome applicazione |
|
||||
| `VITE_APP_URL` | `http://localhost:5173` | URL pubblico app |
|
||||
|
||||
### Backend
|
||||
|
||||
| Variabile | Default | Descrizione |
|
||||
|-----------|---------|-------------|
|
||||
| `PORT` | `3000` | Porta server (interna) |
|
||||
| `DELAY_MS` | `1500` | Delay simulazione API |
|
||||
| `NODE_ENV` | `production` | Ambiente Node |
|
||||
| `CORS_ORIGINS` | `*` | Origini CORS consentite |
|
||||
| `WEBHOOK_BASE_URL` | `https://logwhisperer.ai/webhook` | Base URL webhook |
|
||||
|
||||
## Utilizzo
|
||||
|
||||
### Sviluppo Locale (default)
|
||||
|
||||
```bash
|
||||
# Le variabili di docker-compose.override.yml vengono usate automaticamente
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Sviluppo con configurazione personalizzata
|
||||
|
||||
```bash
|
||||
# Crea un file .env nella root del progetto
|
||||
cat > .env << 'EOF'
|
||||
VITE_API_URL=http://192.168.254.79:3001
|
||||
VITE_WEBHOOK_BASE_URL=http://192.168.254.79:3001/webhook
|
||||
CORS_ORIGINS=*
|
||||
EOF
|
||||
|
||||
# Avvia con le variabili dal file .env
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Produzione con Reverse Proxy
|
||||
|
||||
```bash
|
||||
# 1. Crea il file .env con i valori di produzione
|
||||
cat > .env << 'EOF'
|
||||
VITE_API_URL=https://srv-logwhispererai.lab.home.lucasacchi.net
|
||||
VITE_WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
|
||||
VITE_INSTALL_SCRIPT_URL=https://logwhispererai.lab.home.lucasacchi.net/install.sh
|
||||
VITE_APP_URL=https://logwhispererai.lab.home.lucasacchi.net
|
||||
CORS_ORIGINS=https://logwhispererai.lab.home.lucasacchi.net
|
||||
WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
|
||||
NODE_ENV=production
|
||||
EOF
|
||||
|
||||
# 2. Avvia con la configurazione di produzione
|
||||
# (ignora docker-compose.override.yml)
|
||||
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||
```
|
||||
|
||||
### Solo Backend
|
||||
|
||||
```bash
|
||||
docker compose up fake-backend -d
|
||||
```
|
||||
|
||||
### Solo Frontend
|
||||
|
||||
```bash
|
||||
docker compose up frontend -d
|
||||
```
|
||||
|
||||
## Verifica Configurazione
|
||||
|
||||
```bash
|
||||
# Controlla le variabili caricate
|
||||
docker compose config
|
||||
|
||||
# Verifica il backend
|
||||
curl https://srv-logwhispererai.lab.home.lucasacchi.net/health
|
||||
|
||||
# Verifica la generazione webhook
|
||||
curl -X POST https://srv-logwhispererai.lab.home.lucasacchi.net/api/webhook
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Cambiare le variabili
|
||||
|
||||
Se modifichi il file `.env`, devi ricreare i container:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Vedere le variabili in uso
|
||||
|
||||
```bash
|
||||
# Frontend
|
||||
docker exec logwhisperer-frontend-dev env | grep VITE
|
||||
|
||||
# Backend
|
||||
docker exec logwhisperer-fake-backend env | grep -E '(CORS|WEBHOOK)'
|
||||
```
|
||||
|
||||
### Reset alla configurazione default
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
rm .env # Rimuovi configurazione personalizzata
|
||||
docker compose up -d # Userà i valori default
|
||||
```
|
||||
129
docs/reverse_proxy_setup.md
Normal file
129
docs/reverse_proxy_setup.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# Configurazione con Reverse Proxy
|
||||
|
||||
Questa guida spiega come configurare LogWhispererAI con un reverse proxy SSL.
|
||||
|
||||
## Scenario
|
||||
|
||||
Hai configurato:
|
||||
- **Frontend**: `https://logwhispererai.lab.home.lucasacchi.net` → `http://192.168.254.79:5173`
|
||||
- **Backend**: `https://srv-logwhispererai.lab.home.lucasacchi.net` → `http://192.168.254.79:3001`
|
||||
|
||||
## Configurazione
|
||||
|
||||
### 1. Crea il file di configurazione
|
||||
|
||||
Crea un file `.env` nella root del progetto:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Modifica il file `.env` con i tuoi valori:
|
||||
|
||||
```env
|
||||
# Frontend Configuration
|
||||
VITE_API_URL=https://srv-logwhispererai.lab.home.lucasacchi.net
|
||||
VITE_WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
|
||||
VITE_INSTALL_SCRIPT_URL=https://logwhispererai.lab.home.lucasacchi.net/install.sh
|
||||
VITE_APP_NAME=LogWhispererAI
|
||||
VITE_APP_URL=https://logwhispererai.lab.home.lucasacchi.net
|
||||
|
||||
# Backend Configuration
|
||||
CORS_ORIGINS=https://logwhispererai.lab.home.lucasacchi.net
|
||||
WEBHOOK_BASE_URL=https://logwhispererai.lab.home.lucasacchi.net/webhook
|
||||
DELAY_MS=1500
|
||||
NODE_ENV=production
|
||||
```
|
||||
|
||||
### 2. Avvia i servizi
|
||||
|
||||
```bash
|
||||
# Ferma eventuali container esistenti
|
||||
docker compose down
|
||||
|
||||
# Avvia con le nuove variabili
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### 3. Verifica la configurazione
|
||||
|
||||
Testa i vari endpoint:
|
||||
|
||||
```bash
|
||||
# Health check backend
|
||||
curl https://srv-logwhispererai.lab.home.lucasacchi.net/health
|
||||
|
||||
# Genera un webhook
|
||||
curl -X POST https://srv-logwhispererai.lab.home.lucasacchi.net/api/webhook
|
||||
|
||||
# Analizza un log
|
||||
curl -X POST https://srv-logwhispererai.lab.home.lucasacchi.net/api/analyze \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"log": "FATAL: out of memory"}'
|
||||
```
|
||||
|
||||
### 4. Verifica il frontend
|
||||
|
||||
Apri `https://logwhispererai.lab.home.lucasacchi.net` nel browser e verifica che:
|
||||
1. La demo interattiva funzioni (chiama il backend corretto)
|
||||
2. Lo step 2 dell'onboarding generi webhook con l'URL corretto
|
||||
|
||||
## Variabili d'Ambiente
|
||||
|
||||
### Frontend (VITE_*)
|
||||
|
||||
| Variabile | Descrizione | Esempio |
|
||||
|-----------|-------------|---------|
|
||||
| `VITE_API_URL` | URL del backend API | `https://srv-logwhispererai.lab.home.lucasacchi.net` |
|
||||
| `VITE_WEBHOOK_BASE_URL` | Base URL per i webhook | `https://logwhispererai.lab.home.lucasacchi.net/webhook` |
|
||||
| `VITE_INSTALL_SCRIPT_URL` | URL dello script di installazione | `https://logwhispererai.lab.home.lucasacchi.net/install.sh` |
|
||||
| `VITE_APP_NAME` | Nome dell'applicazione | `LogWhispererAI` |
|
||||
| `VITE_APP_URL` | URL pubblico dell'app | `https://logwhispererai.lab.home.lucasacchi.net` |
|
||||
|
||||
### Backend
|
||||
|
||||
| Variabile | Descrizione | Esempio |
|
||||
|-----------|-------------|---------|
|
||||
| `CORS_ORIGINS` | Origini CORS consentite (comma-separated) | `https://logwhispererai.lab.home.lucasacchi.net` |
|
||||
| `WEBHOOK_BASE_URL` | Base URL per i webhook generati | `https://logwhispererai.lab.home.lucasacchi.net/webhook` |
|
||||
| `DELAY_MS` | Delay simulato API (ms) | `1500` |
|
||||
| `NODE_ENV` | Ambiente Node | `production` |
|
||||
|
||||
## File Configurati
|
||||
|
||||
- `frontend/.env` - Configurazione frontend per produzione
|
||||
- `frontend/.env.development` - Configurazione per sviluppo locale
|
||||
- `frontend/vite.config.ts` - Allow hosts per Vite
|
||||
- `tools/fake-backend/server.js` - Supporto CORS dinamico e webhook URL configurabili
|
||||
- `docker-compose.yml` - Passaggio variabili ai container
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Errore "Blocked request" di Vite
|
||||
|
||||
Se vedi questo errore:
|
||||
```
|
||||
Blocked request. This host ("logwhispererai.lab.home.lucasacchi.net") is not allowed.
|
||||
```
|
||||
|
||||
Aggiungi il dominio a `frontend/vite.config.ts`:
|
||||
```typescript
|
||||
server: {
|
||||
allowedHosts: [
|
||||
'logwhispererai.lab.home.lucasacchi.net',
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Errore CORS
|
||||
|
||||
Se il browser blocca le richieste API:
|
||||
1. Verifica che `CORS_ORIGINS` includa il dominio del frontend
|
||||
2. Ricostruisci il backend: `docker compose up fake-backend --build -d`
|
||||
|
||||
### Webhook URL errati
|
||||
|
||||
Se i webhook generati hanno URL sbagliati:
|
||||
1. Verifica `WEBHOOK_BASE_URL` nel backend
|
||||
2. Verifica `VITE_WEBHOOK_BASE_URL` nel frontend
|
||||
3. Ricostruisci entrambi i servizi
|
||||
Reference in New Issue
Block a user