Fix jwt-token

This commit is contained in:
2025-08-17 06:01:45 +02:00
parent b7ba123f94
commit 8a5978438e
2 changed files with 77 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ const { sequelize } = require('./models');
const routes = require('./routes');
const { initializeSocketHandlers } = require('./services/socketService');
const AlertService = require('./services/alertService');
const seedDatabase = require('./seedDatabase');
const errorHandler = require('./middleware/errorHandler');
const app = express();
@@ -76,9 +77,23 @@ async function startServer() {
await sequelize.authenticate();
console.log('Database connected successfully.');
if (process.env.NODE_ENV !== 'production') {
// Always sync database in containerized environments or development
// Check if tables exist before syncing
try {
await sequelize.sync({ alter: true });
console.log('Database synchronized.');
// Seed database with initial data
await seedDatabase();
} catch (syncError) {
console.error('Database sync error:', syncError);
// If sync fails, try force sync (this will drop and recreate tables)
console.log('Attempting force sync...');
await sequelize.sync({ force: false, alter: true });
console.log('Database force synchronized.');
// Seed database with initial data
await seedDatabase();
}
server.listen(PORT, () => {