mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
using static frontend build path for static expresss
This commit is contained in:
5
.env.production
Normal file
5
.env.production
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# .env.production example
|
||||||
|
NODE_ENV=production
|
||||||
|
JWT_SECRET=your-super-secure-minimum-32-character-secret-key-here
|
||||||
|
DATABASE_PATH=/app/data/production.db
|
||||||
|
FRONTEND_BUILD_PATH=/app/frontend-build
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
"@types/cors": "^2.8.13",
|
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/jsonwebtoken": "^9.0.2",
|
"@types/jsonwebtoken": "^9.0.2",
|
||||||
"@types/uuid": "^9.0.2",
|
"@types/uuid": "^9.0.2",
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ import setupRoutes from './routes/setup.js';
|
|||||||
import scheduledShifts from './routes/scheduledShifts.js';
|
import scheduledShifts from './routes/scheduledShifts.js';
|
||||||
import schedulingRoutes from './routes/scheduling.js';
|
import schedulingRoutes from './routes/scheduling.js';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3002;
|
const PORT = 3002;
|
||||||
|
|
||||||
@@ -39,37 +36,18 @@ app.get('/api/health', (req: any, res: any) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 🆕 FIXED STATIC FILE SERVING
|
// 🆕 STATIC FILE SERVING
|
||||||
// Use absolute path that matches Docker container structure
|
// Use absolute path that matches Docker container structure
|
||||||
const frontendBuildPathEnv = process.env.FRONTEND_BUILD_PATH;
|
|
||||||
console.log('📁 Frontend build path from the env', frontendBuildPathEnv);
|
|
||||||
const frontendBuildPath = path.resolve('/app/frontend-build');
|
const frontendBuildPath = path.resolve('/app/frontend-build');
|
||||||
console.log('📁 Frontend build path:', frontendBuildPath);
|
console.log('📁 Frontend build path:', frontendBuildPath);
|
||||||
console.log('📁 Current __dirname:', __dirname);
|
|
||||||
|
|
||||||
// Check multiple possible locations for frontend build
|
if (frontendBuildPath) {
|
||||||
const possiblePaths = [
|
|
||||||
'/app/frontend-build', // Docker production path
|
|
||||||
path.join(__dirname, '../../frontend-build'), // Relative from dist
|
|
||||||
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(actualFrontendPath));
|
app.use(express.static(frontendBuildPath));
|
||||||
|
|
||||||
// List files for debugging
|
// List files for debugging
|
||||||
try {
|
try {
|
||||||
const files = fs.readdirSync(actualFrontendPath);
|
const files = fs.readdirSync(frontendBuildPath);
|
||||||
console.log('📄 Files in frontend-build:', files);
|
console.log('📄 Files in frontend-build:', files);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('❌ Could not read frontend-build directory:', err);
|
console.log('❌ Could not read frontend-build directory:', err);
|
||||||
@@ -78,16 +56,15 @@ if (actualFrontendPath) {
|
|||||||
console.log('✅ Static file serving configured');
|
console.log('✅ Static file serving configured');
|
||||||
} else {
|
} else {
|
||||||
console.log('❌ Frontend build directory NOT FOUND in any location');
|
console.log('❌ Frontend build directory NOT FOUND in any location');
|
||||||
console.log('❌ Checked paths:', possiblePaths);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root route
|
// Root route
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
if (!actualFrontendPath) {
|
if (!frontendBuildPath) {
|
||||||
return res.status(500).send('Frontend build not found');
|
return res.status(500).send('Frontend build not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPath = path.join(actualFrontendPath, 'index.html');
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
console.log('📄 Serving index.html from:', indexPath);
|
console.log('📄 Serving index.html from:', indexPath);
|
||||||
|
|
||||||
if (fs.existsSync(indexPath)) {
|
if (fs.existsSync(indexPath)) {
|
||||||
@@ -105,11 +82,11 @@ app.get('*', (req, res) => {
|
|||||||
return res.status(404).json({ error: 'API endpoint not found' });
|
return res.status(404).json({ error: 'API endpoint not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actualFrontendPath) {
|
if (!frontendBuildPath) {
|
||||||
return res.status(500).json({ error: 'Frontend application not available' });
|
return res.status(500).json({ error: 'Frontend application not available' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPath = path.join(actualFrontendPath, 'index.html');
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
console.log('🔄 Client-side routing for:', req.path, '->', indexPath);
|
console.log('🔄 Client-side routing for:', req.path, '->', indexPath);
|
||||||
|
|
||||||
if (fs.existsSync(indexPath)) {
|
if (fs.existsSync(indexPath)) {
|
||||||
|
|||||||
3856
package-lock.json
generated
3856
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user