I’m trying to set up API proxying in my Next.js project but running into issues. In my previous React projects using create-react-app, I could easily proxy API calls by creating a proxy configuration file like this:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(application) {
application.use('/backend',
createProxyMiddleware({
target: 'http://localhost:3001',
changeOrigin: true,
})
);
};
However, this approach doesn’t work in Next.js and throws errors when I try to implement it. I’ve seen suggestions about using custom servers, but I want to stick with the built-in Next.js dev server. Is there a way to achieve similar proxy functionality without having to create a custom server setup? I’m using next dev
as my development command and would prefer to keep it that way.