Registration and activation

This commit is contained in:
Torsten Schulz
2024-07-20 20:43:18 +02:00
parent 3880a265eb
commit bbf4a2deb3
51 changed files with 3016 additions and 69 deletions

View File

@@ -2,8 +2,7 @@ import http from 'http';
import { Server } from 'socket.io';
import amqp from 'amqplib/callback_api.js';
import app from './app.js';
import path from 'path';
import express from 'express';
import { syncDatabase } from './utils/syncDatabase.js';
const server = http.createServer(app);
const io = new Server(server);
@@ -11,14 +10,6 @@ const io = new Server(server);
const RABBITMQ_URL = 'amqp://localhost';
const QUEUE = 'chat_messages';
const __dirname = path.resolve();
const frontendPath = path.join(__dirname, 'path/to/your/frontend/build/folder');
app.use(express.static(frontendPath));
app.get('*', (req, res) => {
res.sendFile(path.join(frontendPath, 'index.html'));
});
amqp.connect(RABBITMQ_URL, (err, connection) => {
if (err) {
throw err;
@@ -48,8 +39,14 @@ amqp.connect(RABBITMQ_URL, (err, connection) => {
});
});
server.listen(3001, () => {
console.log('Server is running on port 3001');
// Sync database before starting the server
syncDatabase().then(() => {
server.listen(3001, () => {
console.log('Server is running on port 3001');
});
}).catch(err => {
console.error('Failed to sync database:', err);
process.exit(1);
});
});
});