To proxy to backend with default Next.js dev server, we configure our Next.js config with the URL rewrite.
For instance, in next.config.js, we write
module.exports = {
async rewrites() {
return [
{
source: "/api/:path*",
destination: "http://localhost:8000/:path*",
},
];
},
};
to return an array with an object with the source
path and the destination
path which we redirect the source
path to.
This lets us create a proxy to the back end for our Next.js app