Testing CORS while sending request from a local NextJS server to a local Rails api server

333 views Asked by At

I have two servers both of them running on localhost. On port 3000 it's a NextJs development server and on port 4000 i am running a Rails Api only server. I have not added any extra libraries or packages. I have a api endpoint like http://localhost:4000/products. And i have a fetch request from a NextJs page component's getServerSideProps function. I want to see how CORS works between these two servers. In development mode they are on the same domain localhost. But in production they will be different. How can i test CORS while both of the servers running on localhost?

1

There are 1 answers

0
Jeferson Guedes On BEST ANSWER

In your /etc/hosts you can change the domain from localhost:4000 to api.example.localhost and keep the next one running in the same environment