Vite proxy debugging
SPA developement with a local proxy to server apis is a common technique nowadays. Here's a usefull method to debug proxy if you need to find out why your proxy fail.
defineConfig(mode => {
return {
server: {
proxy: {
// ...proxy config here
},
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target:', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
});
},
},
};
});