First
This commit is contained in:
47
backend/server.js
Normal file
47
backend/server.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const cookieSession = require('cookie-session');
|
||||
|
||||
const storage = require('./src/utils/storage');
|
||||
const adminRoutes = require('./src/routes/admin');
|
||||
const friendRoutes = require('./src/routes/friend');
|
||||
const uploadRoutes = require('./src/routes/uploads');
|
||||
|
||||
storage.ensureBaseDirs();
|
||||
|
||||
const app = express();
|
||||
app.disable('x-powered-by');
|
||||
app.use(express.json({ limit: '2mb' }));
|
||||
|
||||
app.use(
|
||||
cookieSession({
|
||||
name: 'fb_session',
|
||||
secret: process.env.SESSION_SECRET || 'bitte-in-der-docker-compose-aendern',
|
||||
maxAge: 30 * 24 * 60 * 60 * 1000, // 30 Tage
|
||||
sameSite: 'lax',
|
||||
})
|
||||
);
|
||||
|
||||
// --- API ---
|
||||
app.use('/api', adminRoutes);
|
||||
app.use('/api', friendRoutes);
|
||||
app.use('/uploads', uploadRoutes);
|
||||
|
||||
// --- Frontend (statisch) ---
|
||||
const PUBLIC_DIR = path.join(__dirname, 'public');
|
||||
app.use('/assets', express.static(path.join(PUBLIC_DIR, 'shared')));
|
||||
app.use('/admin', express.static(path.join(PUBLIC_DIR, 'admin')));
|
||||
app.use('/friend', express.static(path.join(PUBLIC_DIR, 'friend')));
|
||||
app.use('/book', express.static(path.join(PUBLIC_DIR, 'book')));
|
||||
app.get('/', (req, res) => res.sendFile(path.join(PUBLIC_DIR, 'login', 'index.html')));
|
||||
|
||||
// Friend-Share-Link: /share/<id> -> gleiche Seite wie /friend, JS erkennt ID aus der URL
|
||||
app.get('/share/:id', (req, res) => res.sendFile(path.join(PUBLIC_DIR, 'friend', 'index.html')));
|
||||
app.get('/friend/:id', (req, res) => res.sendFile(path.join(PUBLIC_DIR, 'friend', 'index.html')));
|
||||
|
||||
app.get('/health', (req, res) => res.json({ ok: true }));
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Freundesbuch läuft auf Port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user