modified: backend/src/server.ts
This commit is contained in:
@@ -4,7 +4,6 @@ import helmet from 'helmet';
|
||||
// import rateLimit from 'express-rate-limit';
|
||||
import swaggerUi from 'swagger-ui-express';
|
||||
import path from 'path';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
import { config } from './config/environment';
|
||||
import { initializeDatabase } from './config/database';
|
||||
import { generateDynamicSwagger } from './config/dynamicSwagger';
|
||||
@@ -117,19 +116,22 @@ if (config.nodeEnv === 'production') {
|
||||
});
|
||||
} else {
|
||||
// Development mode - proxy to Vite dev server for non-API routes
|
||||
const viteProxy = createProxyMiddleware({
|
||||
target: 'http://localhost:5173',
|
||||
changeOrigin: true,
|
||||
ws: true, // Enable WebSocket proxying for HMR
|
||||
});
|
||||
// Dynamic import to avoid requiring http-proxy-middleware in production
|
||||
import('http-proxy-middleware').then(({ createProxyMiddleware }) => {
|
||||
const viteProxy = createProxyMiddleware({
|
||||
target: 'http://localhost:5173',
|
||||
changeOrigin: true,
|
||||
ws: true, // Enable WebSocket proxying for HMR
|
||||
});
|
||||
|
||||
app.use((req: Request, res: Response, next: any) => {
|
||||
// If it's an API route or swagger, handle it normally
|
||||
if (req.path.startsWith('/api/') || req.path.startsWith('/api-docs') || req.path === '/health') {
|
||||
return next();
|
||||
}
|
||||
// Otherwise, proxy to Vite dev server
|
||||
return viteProxy(req, res, next);
|
||||
app.use((req: Request, res: Response, next: any) => {
|
||||
// If it's an API route or swagger, handle it normally
|
||||
if (req.path.startsWith('/api/') || req.path.startsWith('/api-docs') || req.path === '/health') {
|
||||
return next();
|
||||
}
|
||||
// Otherwise, proxy to Vite dev server
|
||||
return viteProxy(req, res, next);
|
||||
});
|
||||
});
|
||||
|
||||
// 404 handler for API routes only
|
||||
|
||||
Reference in New Issue
Block a user