Next.js Discord

Discord Forum

Rewrites not working for Server Side component

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Avatar
Northeast Congo LionOP
async function getData() {
  const res = await fetch('/api/user/')
  // The return value is *not* serialized
  // You can return Date, Map, Set, etc.
 
  if (!res.ok) {
    // This will activate the closest `error.js` Error Boundary
    throw new Error('Failed to fetch data')
  }
 
  return res.json()
}
 
export default async function Page() {
  const data = await getData()
 
  return <main></main>
}


module.exports = {
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: 'http://localhost:5000/api/:path*', // Proxy to Backend
      },
    ];
  },
  reactStrictMode: false,
  transpilePackages: ['ui'],
};


I'm trying to run a rewrite to reach my external API, but it doesn't seem to work unless I run it as a client component. It seems that the rewrite does not work on the server side

2 Replies