I have a NextJS project which has an index page:
pages/index.jsx
const Home = NextPage<Props> = (props) => {
...
...
...
}
export default async function getServerSideProps() {
posts = await('http://localhost:8000/posts/')
return {
props: { posts }
}
}
But the domain of the fetch request is being changed to the ipv6 address (::1) and this causes a connection refused error. (Backend server is not accepting ipv6 requests)
My question is why NextJS is doing this on getServerSideProps? (Fetch requests from frontend is not doing the same thing)
Here is some more info about my issue:
URL that trying to be fetched: http://localhost:8000/posts/?ishot=true Options on that fetch request:
{
mode: 'cors',
cache: 'no-cache',
credentials: 'include',
headers: {},
redirect: 'follow',
method: 'GET'
}
The error that I am receiving:
error - TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:14152:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED ::1:8000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 8000
},
page: '/'
}