for github
for github

Reputation: 1

When running the MERN project on the local network, the data is only visible to the server computer due to the CORS problem

I have created a project where data is entered from the admin panel and this data is displayed to users in a table format on the home page. When I run my project on my computer, everything works perfectly on the localhost:3000 url. However, when I type my computer's IP address http://172.16.252.246:3000 and access the program from another computer on the local network, the program opens but cannot output data from the backend to the table. Login registers are also not working.

app.use(cors({ origin: ['http://localhost:3000', 'http://172.16.252.5:3000', 'http://172.16.252.246:3000'], methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], credentials: true, }));

I tried this code. But the problem was not solved.

Upvotes: 0

Views: 23

Answers (1)

Chibuokem Onyekwelu
Chibuokem Onyekwelu

Reputation: 118

You need to configure your server to receive preflight requests and respond appropriately. Check this link for more information: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

Upvotes: 0

Related Questions