Files
yourpart3/backend/server.js
Torsten Schulz (local) 56be4b76c0
All checks were successful
Deploy to production / deploy (push) Successful in 3m3s
feat(political-benefits): implement political powers and benefits system
- Added new political powers and benefits functionalities, including reputation ticks, tax jurisdiction management, and appointment capabilities.
- Introduced a new job for periodic reputation updates and created necessary database tables for tracking political benefits.
- Enhanced the FalukantController and services to support new endpoints for managing political powers and appointments.
- Updated localization files to reflect new features and improve user experience across multiple languages.
- Modified the UI to display new political powers and benefits, ensuring accurate representation in the PoliticsView.
2026-04-02 16:00:29 +02:00

77 lines
3.2 KiB
JavaScript

import './config/loadEnv.js'; // .env deterministisch laden
import http from 'http';
import https from 'https';
import fs from 'fs';
// Assoziationen sofort setzen, bevor app (und damit Services/Router) geladen werden.
// So nutzen alle Modelle dieselbe Instanz inkl. Associations (verhindert EagerLoadingError).
import setupAssociations from './models/associations.js';
setupAssociations();
import app from './app.js';
import { setupWebSocket } from './utils/socket.js';
import { syncDatabase } from './utils/syncDatabase.js';
// HTTP-Server für API (Port 2020, intern, über Apache-Proxy)
const API_PORT = Number.parseInt(process.env.API_PORT || process.env.PORT || '2020', 10);
const API_HOST = process.env.API_HOST || '127.0.0.1';
const httpServer = http.createServer(app);
// Socket.io wird nur auf HTTPS-Server bereitgestellt, nicht auf HTTP-Server
// setupWebSocket(httpServer); // Entfernt: Socket.io nur über HTTPS
// HTTPS-Server für Socket.io (Port 4443, direkt erreichbar)
let httpsServer = null;
const SOCKET_IO_PORT = Number.parseInt(process.env.SOCKET_IO_PORT || '4443', 10);
const USE_TLS = process.env.SOCKET_IO_TLS === '1';
const TLS_KEY_PATH = process.env.SOCKET_IO_TLS_KEY_PATH;
const TLS_CERT_PATH = process.env.SOCKET_IO_TLS_CERT_PATH;
const TLS_CA_PATH = process.env.SOCKET_IO_TLS_CA_PATH;
const SOCKET_IO_HOST = process.env.SOCKET_IO_HOST || '0.0.0.0';
if (USE_TLS && TLS_KEY_PATH && TLS_CERT_PATH) {
try {
httpsServer = https.createServer({
key: fs.readFileSync(TLS_KEY_PATH),
cert: fs.readFileSync(TLS_CERT_PATH),
ca: TLS_CA_PATH ? fs.readFileSync(TLS_CA_PATH) : undefined,
}, app);
setupWebSocket(httpsServer);
console.log(`[Socket.io] HTTPS-Server für Socket.io konfiguriert auf Port ${SOCKET_IO_PORT}`);
} catch (err) {
console.error('[Socket.io] Fehler beim Laden der TLS-Zertifikate:', err.message);
console.error('[Socket.io] Socket.io wird nicht verfügbar sein');
}
} else {
console.warn('[Socket.io] TLS nicht konfiguriert - Socket.io wird nicht verfügbar sein');
}
syncDatabase().then(() => {
if (process.env.FALUKANT_POLITICAL_REPUTATION_JOB === '1') {
const intervalMs = Number.parseInt(process.env.FALUKANT_POLITICAL_REPUTATION_MS || '3600000', 10);
import('./jobs/politicalBenefitsTick.js')
.then(({ runPoliticalReputationTicks }) => {
const run = () =>
runPoliticalReputationTicks().catch((e) => console.error('[PoliticalBenefits]', e));
run();
setInterval(run, intervalMs);
console.log(`[PoliticalBenefits] Job aktiv, Intervall ${intervalMs} ms`);
})
.catch((e) => console.error('[PoliticalBenefits] Job-Import fehlgeschlagen:', e));
}
// API-Server auf Port 2020 (intern, nur localhost)
httpServer.listen(API_PORT, API_HOST, () => {
console.log(`[API] HTTP-Server läuft auf ${API_HOST}:${API_PORT}`);
});
// Socket.io-Server auf Port 4443 (extern, direkt erreichbar)
if (httpsServer) {
httpsServer.listen(SOCKET_IO_PORT, SOCKET_IO_HOST, () => {
console.log(`[Socket.io] HTTPS-Server läuft auf ${SOCKET_IO_HOST}:${SOCKET_IO_PORT}`);
});
}
}).catch(err => {
console.error('Failed to sync database:', err);
process.exit(1);
});