'Error only shows the first time using Axios on getInitialProps

Hi everyone i've an issue fetching data with Axios

Let me explain to you what im doing: i've my FrontEnd made in NextJs but my BackEnd was made on C# then when i try to fetch data in getInitialProps with axios

enter image description here

The error shows only the first time when i load the page shows:

console error

My Network

enter image description here

But when i refresh the page all works fine

enter image description here

I'm aware that i can't fetch data using localhost without enable CORS

I´ve been looking a lot and found that i've to enabled on my custom server

enter image description here

UPDATE:

I used this for OPTION methods

enter image description here

Because i found in the network tab this error

enter image description here

But still not working, maybe i'm missing something or some configuration

If you need more information please let me know

MY SOLUTION

I've found the solution, i used getServerSideProps instead of getInitialProps and it works



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source