diff --git a/server/index.production.ts b/server/index.production.ts index 0a20be1..2549200 100644 --- a/server/index.production.ts +++ b/server/index.production.ts @@ -48,6 +48,12 @@ async function registerProductionRoutes(app: Express): Promise { console.log('🔄 Running automatic production migrations...'); await runProductionMigrations(); + // Initialize weather system for production + console.log('🌤️ [PRODUCTION] Initializing weather system...'); + const { initializeWeatherConfig } = await import('./weatherAutoConfig.js'); + await initializeWeatherConfig(); + console.log('✅ [PRODUCTION] Weather system initialized'); + // Register ALL API routes (same as development) await registerRoutes(app); console.log('✅ All routes registered successfully for production'); diff --git a/server/index.ts b/server/index.ts index 3625700..732238b 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2,11 +2,11 @@ import express, { type Request, Response, NextFunction } from "express"; import { registerRoutes } from "./routes.js"; import { setupVite, serveStatic } from "./vite.js"; -// Initialize simple weather system -console.log('🌤️ [STARTUP] Initializing simple weather system...'); -const { default: simpleWeather } = await import('./simpleWeather.js'); -await simpleWeather.init(); -console.log('✅ [STARTUP] Simple weather initialized'); +// Initialize weather system +console.log('🌤️ [STARTUP] Initializing weather system...'); +const { initializeWeatherConfig } = await import('./weatherAutoConfig.js'); +await initializeWeatherConfig(); +console.log('✅ [STARTUP] Weather system initialized'); const app = express(); diff --git a/server/routes.ts b/server/routes.ts index 5472366..3330563 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -2849,11 +2849,6 @@ RÉSUMÉ DU SCAN app.get('/api/weather/current', isAuthenticated, async (req: any, res) => { try { - const user = await storage.getUserWithGroups(req.user.claims ? req.user.claims.sub : req.user.id); - if (!user || user.role !== 'admin') { - return res.status(403).json({ message: "Access denied - Admin only" }); - } - const settings = await storage.getWeatherSettings(); if (!settings || !settings.isActive) { diff --git a/server/simpleWeather.js b/server/simpleWeather.js deleted file mode 100644 index 9b2ffc8..0000000 --- a/server/simpleWeather.js +++ /dev/null @@ -1,39 +0,0 @@ -// Simple weather service for development -const weatherCache = { - today: { - date: '2025-08-11', - location: 'Nancy, France', - tempMax: '30.9', - tempMin: '13.9', - icon: 'clear-day', - conditions: 'Clear', - isCurrentYear: true - }, - previousYear: { - date: '2024-08-11', - location: 'Nancy, France', - tempMax: '30.9', - tempMin: '15.8', - icon: 'clear-day', - conditions: 'Clear', - isCurrentYear: false - }, - lastFetch: new Date().toISOString() -}; - -const simpleWeather = { - async init() { - console.log('🌤️ [UPDATE] Fetching fresh weather data...'); - console.log('🌤️ [FETCH] Calling: Nancy, France for 2025-08-11'); - console.log('🌤️ [FETCH] Calling: Nancy, France for 2024-08-11'); - console.log('✅ [UPDATE] Today data cached'); - console.log('✅ [UPDATE] Last year data cached'); - console.log('✅ [UPDATE] Weather cache updated at ' + new Date().toISOString()); - }, - - getData() { - return weatherCache; - } -}; - -export default simpleWeather; \ No newline at end of file diff --git a/server/weatherAutoConfig.ts b/server/weatherAutoConfig.ts new file mode 100644 index 0000000..837471e --- /dev/null +++ b/server/weatherAutoConfig.ts @@ -0,0 +1,64 @@ +/** + * Auto-configuration du système météo pour la production + * Configure automatiquement les paramètres météo avec la clé API des variables d'environnement + */ + +import { storage } from "./storage.js"; +import { weatherService } from "./weatherService.js"; + +export async function initializeWeatherConfig() { + try { + console.log('🌤️ [AUTO-CONFIG] Initializing weather configuration...'); + + // Vérifier si la configuration météo existe déjà + const existingSettings = await storage.getWeatherSettings(); + + if (existingSettings && existingSettings.isActive) { + console.log('✅ [AUTO-CONFIG] Weather settings already configured and active'); + return; + } + + // Récupérer la clé API depuis les variables d'environnement + const apiKey = process.env.VISUAL_CROSSING_API_KEY; + + if (!apiKey) { + console.log('⚠️ [AUTO-CONFIG] VISUAL_CROSSING_API_KEY not found in environment variables'); + return; + } + + // Configuration par défaut + const defaultConfig = { + apiKey: apiKey, + location: "Nancy, France", + isActive: true + }; + + console.log('🌤️ [AUTO-CONFIG] Testing API connection...'); + + // Tester la connexion API avant de sauvegarder + const testResult = await weatherService.testApiConnection(defaultConfig.apiKey, defaultConfig.location); + + if (!testResult.success) { + console.error('❌ [AUTO-CONFIG] API test failed:', testResult.message); + return; + } + + console.log('✅ [AUTO-CONFIG] API test successful'); + + // Créer ou mettre à jour la configuration + if (existingSettings) { + // Mettre à jour la configuration existante + await storage.updateWeatherSettings(existingSettings.id, defaultConfig); + console.log('🔄 [AUTO-CONFIG] Weather settings updated'); + } else { + // Créer une nouvelle configuration + await storage.createWeatherSettings(defaultConfig); + console.log('🆕 [AUTO-CONFIG] Weather settings created'); + } + + console.log('✅ [AUTO-CONFIG] Weather system successfully configured'); + + } catch (error) { + console.error('❌ [AUTO-CONFIG] Failed to initialize weather config:', error); + } +} \ No newline at end of file