Next.js Discord

Discord Forum

Rewrites dropping port number

Matt posted this in #help-forum
Open in Discord
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
at createConnectionError (node:net:1634:14)
at afterConnectMultiple (node:net:1664:40)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4078,
syscall: 'connect',
address: '',
port: 80

0 Replies