Änderungen am TAgebuch

This commit is contained in:
Torsten Schulz
2024-08-30 11:50:54 +02:00
parent 828035d339
commit 1ac1fc9ca0
116 changed files with 6859 additions and 6765 deletions

View File

@@ -2,10 +2,13 @@ import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import sequelize from './database.js';
import './models/index.js'; // Stellt sicher, dass die Modelle und Beziehungen geladen werden
import { User, Log, Club, UserClub } from './models/index.js';
import authRoutes from './routes/authRoutes.js';
import clubRoutes from './routes/clubRoutes.js'
import clubRoutes from './routes/clubRoutes.js';
import diaryRoutes from './routes/diaryRoutes.js';
import memberRoutes from './routes/memberRoutes.js';
import Member from './models/Member.js';
import DiaryDate from './models/DiaryDates.js';
const app = express();
const port = process.env.PORT || 3000;
@@ -17,6 +20,7 @@ app.use(express.json());
app.use('/api/auth', authRoutes);
app.use('/api/clubs', clubRoutes);
app.use('/api/clubmembers', memberRoutes);
app.use('/api/diary', diaryRoutes);
app.use(express.static(path.join(__dirname, '../frontend/dist')));
@@ -24,10 +28,19 @@ app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../frontend/dist/index.html'));
});
sequelize.sync({ alter: true }).then(() => {
console.log('Database synchronized');
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
(async () => {
try {
await sequelize.authenticate();
await User.sync({ alter: true });
await Club.sync({ alter: true });
await UserClub.sync({ alter: true });
await Log.sync({ alter: true });
await Member.sync({ alter: true });
await DiaryDate.sync({ alter: true });
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
} catch (err) {
console.error('Unable to synchronize the database:', err);
}
})();