changed production routing for frontend build

This commit is contained in:
2025-10-26 16:56:50 +01:00
parent b11c55c1d9
commit 93a52aa196
2 changed files with 57 additions and 31 deletions

View File

@@ -39,26 +39,53 @@ app.get('/api/health', (req: any, res: any) => {
}); });
}); });
// 🆕 STATIC FILE SERVING FÜR FRONTEND // 🆕 FIXED STATIC FILE SERVING
const frontendBuildPath = process.env.FRONTEND_BUILD_PATH || '../frontend-build'; // Use absolute path that matches Docker container structure
const frontendBuildPath = path.resolve('/app/frontend-build');
console.log('📁 Frontend build path:', frontendBuildPath); console.log('📁 Frontend build path:', frontendBuildPath);
console.log('📁 Current __dirname:', __dirname);
// Überprüfe ob das Verzeichnis existiert // Check multiple possible locations for frontend build
if (fs.existsSync(frontendBuildPath)) { const possiblePaths = [
console.log('✅ Frontend build directory exists'); '/app/frontend-build', // Docker production path
const files = fs.readdirSync(frontendBuildPath); path.join(__dirname, '../../frontend-build'), // Relative from dist
console.log('📄 Files in frontend-build:', files); path.join(process.cwd(), 'frontend-build'), // From current working directory
];
let actualFrontendPath = null;
for (const testPath of possiblePaths) {
if (fs.existsSync(testPath)) {
actualFrontendPath = testPath;
console.log('✅ Found frontend build at:', testPath);
break;
}
}
if (actualFrontendPath) {
// Serviere statische Dateien // Serviere statische Dateien
app.use(express.static(frontendBuildPath)); app.use(express.static(actualFrontendPath));
// List files for debugging
try {
const files = fs.readdirSync(actualFrontendPath);
console.log('📄 Files in frontend-build:', files);
} catch (err) {
console.log('❌ Could not read frontend-build directory:', err);
}
console.log('✅ Static file serving configured'); console.log('✅ Static file serving configured');
} else { } else {
console.log('❌ Frontend build directory NOT FOUND:', frontendBuildPath); console.log('❌ Frontend build directory NOT FOUND in any location');
console.log('❌ Checked paths:', possiblePaths);
} }
// Root route
app.get('/', (req, res) => { app.get('/', (req, res) => {
const indexPath = path.join(frontendBuildPath, 'index.html'); if (!actualFrontendPath) {
return res.status(500).send('Frontend build not found');
}
const indexPath = path.join(actualFrontendPath, 'index.html');
console.log('📄 Serving index.html from:', indexPath); console.log('📄 Serving index.html from:', indexPath);
if (fs.existsSync(indexPath)) { if (fs.existsSync(indexPath)) {
@@ -69,19 +96,30 @@ app.get('/', (req, res) => {
} }
}); });
// Client-side routing fallback
app.get('*', (req, res) => { app.get('*', (req, res) => {
// Ignoriere API Routes // Ignoriere API Routes
if (req.path.startsWith('/api/')) { if (req.path.startsWith('/api/')) {
return res.status(404).json({ error: 'API endpoint not found' }); return res.status(404).json({ error: 'API endpoint not found' });
} }
const indexPath = path.join(frontendBuildPath, 'index.html'); if (!actualFrontendPath) {
console.log('🔄 Client-side routing for:', req.path, '-> index.html'); return res.status(500).json({ error: 'Frontend application not available' });
}
const indexPath = path.join(actualFrontendPath, 'index.html');
console.log('🔄 Client-side routing for:', req.path, '->', indexPath);
if (fs.existsSync(indexPath)) { if (fs.existsSync(indexPath)) {
res.sendFile(indexPath); // Use absolute path with res.sendFile
res.sendFile(indexPath, (err) => {
if (err) {
console.error('Error sending index.html:', err);
res.status(500).send('Error loading application');
}
});
} else { } else {
console.error('❌ index.html not found for client-side routing'); console.error('❌ index.html not found for client-side routing at:', indexPath);
res.status(404).json({ error: 'Frontend application not found' }); res.status(404).json({ error: 'Frontend application not found' });
} }
}); });

View File

@@ -1,26 +1,14 @@
version: '3.8' version: '3.8'
services: services:
schichtplan: schichtplaner:
build: container_name: schichtplaner
context: . image: ghcr.io/donpat1to/schichtenplaner:v1.0.0
dockerfile: backend/Dockerfile
ports: ports:
- "3001:3001" - "3002:3002"
- "3000:3000"
environment:
- NODE_ENV=production
- DATABASE_URL=file:./prod.db
- JWT_SECRET=your-production-secret-key-change-this
- PYTHON_PATH=/usr/bin/python3
volumes: volumes:
- app_data:/app/data - app_data:/app/data
restart: unless-stopped restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
interval: 30s
timeout: 10s
retries: 3
volumes: volumes:
app_data: app_data: