Next.js Discord

Discord Forum

Rewrites dropping port number

Unanswered
Matt posted this in #help-forum
Open in Discord
Avatar
MattOP
I'm trying to make a request on the server (using app dir) to http://localhost:5000/api/pets. Everything works on the client, but when it runs on the server Axios throws an error. From the error, I can see the URL is: _currentUrl: 'http://localhost/api/pets' - it looks like it's dropping the port number.

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: "/api/:path",
        destination: "http://localhost:5000/:path",
      },
    ];
  },
};

module.exports = nextConfig;


Full error:

Error: connect ECONNREFUSED 127.0.0.1:80
at createConnectionError (node:net:1634:14)
at afterConnectMultiple (node:net:1664:40)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80
}
],

0 Replies