const express = require('express'); const path = require('path'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); const PORT = process.env.PORT || 3000; // Request logging middleware app.use((req, res, next) => { console.log(`[Frontend Server] ${req.method} ${req.url}`); next(); }); // Proxy API requests const backendUrl = process.env.BACKEND_URL || 'http://backend:5000'; const proxyConfig = (pathPrefix) => ({ target: `${backendUrl}${pathPrefix}`, changeOrigin: true, logLevel: 'debug', onProxyReq: (proxyReq, req, res) => { console.log(`[Proxy] Proxying ${req.method} ${req.url} -> ${backendUrl}${pathPrefix}${req.url}`); } }); app.use('/auth', createProxyMiddleware(proxyConfig('/auth'))); app.use('/restaurants', createProxyMiddleware(proxyConfig('/restaurants'))); app.use('/admin', createProxyMiddleware(proxyConfig('/admin'))); // Serve static files from the React app app.use(express.static(path.join(__dirname, 'client/dist'))); app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'client/dist/index.html')); }); app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });