chore: initial scaffold (Whitelabel-Fork von Pfandsystem)
- Source-Copy von /root/entwicklung/pfandsystem - docker-compose.yml umgeschrieben: pfandsystem-demo-* Container, Ports 3308/8083/3003 (alle localhost) - Traefik-Label fuer pfandsystem.dockly.de - Erweitertes Multi-Tenant-Schema (tenants, tenant_id auf allen Tabellen) - Neue Tabellen: kunden_bilder, geraete - Neue Spalten: kunden.anlieferungshinweis, kunden.lieferzeit_bis - Rollen: superadmin, admin, user, fahrer - .env.example + README Code-Refactor (Tailwind, Multi-Tenant-Middleware, Erweiterungen) folgt.
This commit is contained in:
72
backend/server.js
Normal file
72
backend/server.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
// Routes
|
||||
import authRoutes from './routes/auth.js';
|
||||
import kundenRoutes from './routes/kunden.js';
|
||||
import artikelRoutes from './routes/artikel.js';
|
||||
import lieferungenRoutes from './routes/lieferungen.js';
|
||||
import ruecknahmenRoutes from './routes/ruecknahmen.js';
|
||||
import mitarbeiterRoutes from './routes/mitarbeiter.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Statische Dateien (Uploads)
|
||||
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
||||
|
||||
// Health Check
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'OK', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
// API Routes
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api/kunden', kundenRoutes);
|
||||
app.use('/api/artikel', artikelRoutes);
|
||||
app.use('/api/lieferungen', lieferungenRoutes);
|
||||
app.use('/api/ruecknahmen', ruecknahmenRoutes);
|
||||
app.use('/api/mitarbeiter', mitarbeiterRoutes);
|
||||
|
||||
// Error Handler
|
||||
app.use((err, req, res, next) => {
|
||||
console.error('Fehler:', err);
|
||||
|
||||
if (err.name === 'MulterError') {
|
||||
if (err.code === 'LIMIT_FILE_SIZE') {
|
||||
return res.status(400).json({ error: 'Datei zu groß (max. 10MB)' });
|
||||
}
|
||||
return res.status(400).json({ error: err.message });
|
||||
}
|
||||
|
||||
res.status(err.status || 500).json({
|
||||
error: err.message || 'Interner Serverfehler'
|
||||
});
|
||||
});
|
||||
|
||||
// 404 Handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({ error: 'Route nicht gefunden' });
|
||||
});
|
||||
|
||||
// Server starten
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`🚀 Backend-Server läuft auf Port ${PORT}`);
|
||||
console.log(`📊 Health Check: http://localhost:${PORT}/health`);
|
||||
console.log(`🔐 API Base URL: http://localhost:${PORT}/api`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user