diff --git a/backend/index.js b/backend/index.js index 2d346f6..1e71a9e 100644 --- a/backend/index.js +++ b/backend/index.js @@ -1,7 +1,6 @@ - import express from 'express'; import cors from 'cors'; -import { checkConnection, query } from './db.js'; +import { checkConnection, query, initDb } from './db.js'; const app = express(); const PORT = process.env.PORT || 3000; @@ -41,7 +40,15 @@ app.get('/api/tickets', async (req, res) => { } }); -app.listen(PORT, () => { - console.log(`🚀 Backend Server running on port ${PORT}`); - checkConnection(); // Initial check -}); +// Avvio del server +const startServer = async () => { + // Attendi inizializzazione DB (creazione tabelle se necessario) + await initDb(); + + app.listen(PORT, () => { + console.log(`🚀 Backend Server running on port ${PORT}`); + checkConnection(); // Initial check + }); +}; + +startServer();