dropping console on production

This commit is contained in:
2025-10-28 19:20:19 +01:00
parent 5f8a6bef31
commit b3b3250f23
2 changed files with 76 additions and 39 deletions

View File

@@ -93,7 +93,7 @@ if (frontendBuildPath) {
}
// Root route
app.get('/', (req, res) => {
app.get('/', apiLimiter, (req, res) => {
if (!frontendBuildPath) {
return res.status(500).send('Frontend build not found');
}
@@ -110,7 +110,7 @@ app.get('/', (req, res) => {
});
// Client-side routing fallback
app.get('*', (req, res) => {
app.get('*', apiLimiter, (req, res) => {
// Ignoriere API Routes
if (req.path.startsWith('/api/')) {
return res.status(404).json({ error: 'API endpoint not found' });
@@ -137,12 +137,34 @@ app.get('*', (req, res) => {
}
});
// Production error handling - don't leak stack traces
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
console.error('Error:', err);
if (process.env.NODE_ENV === 'production') {
res.status(500).json({
error: 'Internal server error',
message: 'Something went wrong'
});
} else {
res.status(500).json({
error: 'Internal server error',
message: err.message,
stack: err.stack
});
}
});
// Error handling middleware
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
console.error('Unhandled error:', err);
res.status(500).json({ error: 'Internal server error' });
});
app.use('*', (req, res) => {
res.status(404).json({ error: 'Endpoint not found' });
});
// Initialize the application
const initializeApp = async () => {
try {