mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
dropping console on production
This commit is contained in:
@@ -93,7 +93,7 @@ if (frontendBuildPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Root route
|
// Root route
|
||||||
app.get('/', (req, res) => {
|
app.get('/', apiLimiter, (req, res) => {
|
||||||
if (!frontendBuildPath) {
|
if (!frontendBuildPath) {
|
||||||
return res.status(500).send('Frontend build not found');
|
return res.status(500).send('Frontend build not found');
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ app.get('/', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Client-side routing fallback
|
// Client-side routing fallback
|
||||||
app.get('*', (req, res) => {
|
app.get('*', apiLimiter, (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' });
|
||||||
@@ -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
|
// Error handling middleware
|
||||||
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
console.error('Unhandled error:', err);
|
console.error('Unhandled error:', err);
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use('*', (req, res) => {
|
||||||
|
res.status(404).json({ error: 'Endpoint not found' });
|
||||||
|
});
|
||||||
|
|
||||||
// Initialize the application
|
// Initialize the application
|
||||||
const initializeApp = async () => {
|
const initializeApp = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,45 +1,60 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
plugins: [react()],
|
// Load env file based on `mode` in the current directory
|
||||||
server: {
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
port: 3003,
|
|
||||||
host: true,
|
// Only expose specific environment variables to the client
|
||||||
open: true,
|
const clientEnv = {
|
||||||
proxy: {
|
NODE_ENV: mode,
|
||||||
'/api': {
|
ENABLE_PRO: env.ENABLE_PRO || 'false',
|
||||||
target: 'http://localhost:3002',
|
VITE_APP_TITLE: env.VITE_APP_TITLE || 'Shift Planning App',
|
||||||
changeOrigin: true,
|
// Add other client-safe variables here
|
||||||
secure: false,
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: [react()],
|
||||||
|
server: {
|
||||||
|
port: 3003,
|
||||||
|
host: true,
|
||||||
|
open: mode === 'development',
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:3002',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
build: {
|
||||||
build: {
|
outDir: 'dist',
|
||||||
outDir: 'dist',
|
sourcemap: mode === 'development',
|
||||||
sourcemap: true,
|
minify: mode === 'production' ? 'terser' : false,
|
||||||
rollupOptions: {
|
terserOptions: mode === 'production' ? {
|
||||||
input: {
|
compress: {
|
||||||
main: resolve(__dirname, 'index.html')
|
drop_console: true,
|
||||||
|
},
|
||||||
|
} : undefined,
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': resolve(__dirname, './src'),
|
||||||
|
'@/components': resolve(__dirname, './src/components'),
|
||||||
|
'@/pages': resolve(__dirname, './src/pages'),
|
||||||
|
'@/contexts': resolve(__dirname, './src/contexts'),
|
||||||
|
'@/models': resolve(__dirname, './src/models'),
|
||||||
|
'@/utils': resolve(__dirname, './src/utils'),
|
||||||
|
'@/services': resolve(__dirname, './src/services'),
|
||||||
|
'@/design': resolve(__dirname, './src/design')
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
// ✅ SICHER: Nur explizit definierte Variablen
|
||||||
resolve: {
|
define: Object.keys(clientEnv).reduce((acc, key) => {
|
||||||
alias: {
|
acc[`process.env.${key}`] = JSON.stringify(clientEnv[key])
|
||||||
'@': resolve(__dirname, './src'),
|
return acc
|
||||||
'@/components': resolve(__dirname, './src/components'),
|
}, {} as Record<string, string>)
|
||||||
'@/pages': resolve(__dirname, './src/pages'),
|
|
||||||
'@/contexts': resolve(__dirname, './src/contexts'),
|
|
||||||
'@/models': resolve(__dirname, './src/models'),
|
|
||||||
'@/utils': resolve(__dirname, './src/utils'),
|
|
||||||
'@/services': resolve(__dirname, './src/services'),
|
|
||||||
'@/design': resolve(__dirname, './src/design')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Define environment variables
|
|
||||||
define: {
|
|
||||||
'process.env': process.env
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user