I am using react-query prefetchQuery and NextJS (v.13) getServerSideProps along with its rewrites option in next.config.js file to proxy API calls.
The rewrites looks like this:
async rewrites() {
return [
{
source: "/api/:slug*",
destination: "http://test.example.com/api/:slug*",
},
];
},
The problem is, this proxying does not work in getServerSideProps. The API response is 404 not Found.
Here is what I am doing in getServerSideProps:
const queryClient = new QueryClient();
await Promise.all([queryClient.prefetchQuery(["getData"], async () => await getData())]);
where the EndPoint being called in getData is /api/get_page_data.
But everything works fine when I change the EndPoint to an absolute URL, like http://test.example.com/api/get_page_data.
P.S.: I am using Axios for calling APIs, in case this info is helpful.