45 lines
1.9 KiB
JavaScript
45 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
require('./db'); // Datenbank + Tabellen initialisieren
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
// ── Core-Routen ───────────────────────────────────────────────────────────────
|
|
app.use('/api/auth', require('./routes/auth'));
|
|
app.use('/api/admin', require('./routes/admin'));
|
|
app.use('/api/dashboard', require('./routes/dashboard'));
|
|
app.use('/api/system', require('./routes/system'));
|
|
|
|
// ── Tool-Routen automatisch laden ─────────────────────────────────────────────
|
|
// Neues Tool: Datei unter src/tools/<name>/routes.js ablegen → wird automatisch eingebunden
|
|
const toolsDir = path.join(__dirname, 'tools');
|
|
fs.readdirSync(toolsDir, { withFileTypes: true })
|
|
.filter(d => d.isDirectory())
|
|
.forEach(d => {
|
|
const routeFile = path.join(toolsDir, d.name, 'routes.js');
|
|
if (fs.existsSync(routeFile)) {
|
|
app.use(`/api/tools/${d.name}`, require(routeFile));
|
|
console.log(` 🔧 Tool geladen: ${d.name}`);
|
|
}
|
|
});
|
|
|
|
// ── React-Frontend ausliefern ─────────────────────────────────────────────────
|
|
const PUBLIC = path.join(__dirname, '../public');
|
|
|
|
// Service Worker braucht diesen Header damit er auf '/' zugreifen darf
|
|
app.use((req, res, next) => {
|
|
if (req.path === '/sw.js') {
|
|
res.setHeader('Service-Worker-Allowed', '/');
|
|
res.setHeader('Cache-Control', 'no-cache');
|
|
}
|
|
next();
|
|
});
|
|
|
|
app.use(express.static(PUBLIC));
|
|
app.get('*', (_req, res) => res.sendFile(path.join(PUBLIC, 'index.html')));
|
|
|
|
app.listen(4000, () => console.log('🚀 Dicken Dock läuft auf Port 4000'));
|