Update index.js

This commit is contained in:
fcarraUniSa
2026-02-17 00:38:21 +01:00
committed by GitHub
parent 4d74c1232c
commit d349e45d75

View File

@@ -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, () => {
// 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();