Reputation: 7743
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?
Upvotes: 5
Views: 15998
Reputation: 35473
Just remove the domain part from the destination and use absolute
path.
rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: '/:path*' },
// ------------------------------------^
];
Upvotes: 5