GET /users-api Users Proxy - Original URL: /users-api Users Proxy - Forwarding to: http://localhost/ it is not even hitting 4000 if i do like target: 'http://localhost:4000/api/users', directly set target this works fine
// Create proxy middleware for users API
const usersProxy = createProxyMiddleware({
target: 'http://localhost:4000',
changeOrigin: true,
pathRewrite: {
'^/users-api': '/api/users'
},
on: {
proxyReq: (proxyReq, req, res) => {
proxyReq.setHeader('X-Proxy-Service', 'users');
const targetUrl = `${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}`;
console.log('Users Proxy - Original URL:', req.originalUrl);
console.log('Users Proxy - Forwarding to:', targetUrl);
},
proxyRes: (proxyRes, req, res) => {
proxyRes.headers['x-proxied-by'] = 'users-proxy';
},
error: (err, req, res) => {
console.error('Users Proxy Error:', err);
res.status(500).json({
error: 'Users Proxy Error',
message: err.message
});
}
}
});
// Apply proxy middlewares to specific routes
app.use('/users-api',usersProxy);
**GET /users-api Users Proxy - Original URL: /users-api Users Proxy - Forwarding to: http://localhost/ it is not even hitting 4000 if i do like target: 'http://localhost:4000/api/users', directly set target this works fine**