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:
Luca Sacchi Ricciardi
2026-04-03 18:49:53 +02:00
parent 92217897ca
commit 26879acba4
12 changed files with 607 additions and 39 deletions

View File

@@ -15,12 +15,19 @@ const app = express();
const PORT = process.env.PORT || 3000;
const DELAY_MS = parseInt(process.env.DELAY_MS) || 1500;
// Enable CORS for all origins (development only!)
app.use(cors({
origin: '*',
methods: ['GET', 'POST'],
allowedHeaders: ['Content-Type']
}));
// CORS configuration - supports multiple origins via env var
// CORS_ORIGINS can be comma-separated list or '*' for all
const corsOrigins = process.env.CORS_ORIGINS || '*';
const corsOptions = corsOrigins === '*'
? { origin: '*', methods: ['GET', 'POST'], allowedHeaders: ['Content-Type'] }
: {
origin: corsOrigins.split(',').map(o => o.trim()),
methods: ['GET', 'POST'],
allowedHeaders: ['Content-Type'],
credentials: true
};
app.use(cors(corsOptions));
// Parse JSON bodies
app.use(express.json());
@@ -161,6 +168,47 @@ app.post('/api/analyze', (req, res) => {
}, DELAY_MS);
});
// Environment configuration for webhook URLs
const WEBHOOK_BASE_URL = process.env.WEBHOOK_BASE_URL || 'https://logwhisperer.ai/webhook';
/**
* POST /api/webhook
* Generate a fake webhook URL for onboarding
*/
app.post('/api/webhook', (req, res) => {
// Simulate generation delay (500ms - 1s)
const delay = Math.floor(Math.random() * 500) + 500;
setTimeout(() => {
try {
// Generate fake UUID v4
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
res.json({
success: true,
webhookUrl: `${WEBHOOK_BASE_URL}/${uuid}`,
uuid: uuid,
meta: {
generatedAt: new Date().toISOString(),
expiresIn: '30 days'
}
});
} catch (error) {
console.error('Error generating webhook:', error);
res.status(500).json({
success: false,
error: 'Internal Server Error',
message: 'Errore durante la generazione del webhook',
timestamp: new Date().toISOString()
});
}
}, delay);
});
/**
* GET /health
* Health check endpoint
@@ -202,8 +250,8 @@ app.use((err, req, res, next) => {
});
});
// Start server
app.listen(PORT, () => {
// Start server - listen on all interfaces (0.0.0.0) to allow external connections
app.listen(PORT, '0.0.0.0', () => {
console.log(`
╔══════════════════════════════════════════════════════════════╗
║ LogWhispererAI - Fake Backend Server ║
@@ -212,8 +260,9 @@ app.listen(PORT, () => {
║ 📖 Documentation: docs/tools_fake_backend.md ║
║ ⏱️ Simulated delay: ${DELAY_MS}ms ║
║ ║
║ Endpoints: ║
║ Endpoints: ║
║ POST /api/analyze - Analyze log and get mock AI response ║
║ POST /api/webhook - Generate fake webhook URL ║
║ GET /health - Health check ║
║ ║
║ Press Ctrl+C to stop ║