NextJS rewrites in production

Viewed 8903

I discovered rewrites to proxy to my back end server in development:

https://nextjs.org/docs/api-reference/next.config.js/rewrites

rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: 'http://localhost:8080/:path*' },
],

How does this work in production if the url will not be localhost?

For the destination do i need to add the full domain or do i need a separate rewrite rules for dev/production?

1 Answers

Just remove the domain part from the destination and use absolute path.

rewrites: async () => [
  ...nextI18NextRewrites(localeSubpaths),
  { source: '/api/:path*', destination: '/:path*' },
  // ------------------------------------^
];

Related