简体   繁体   中英

Connection working from React to NodeJS, but request-url is incorrect in Chrome Network

enter image description here enter image description here enter image description here Assalamu 'Alaykum

my React app is running on localhost:3000 NodeJS server is running on localhost:1000

I'm sending request to server 'localhost:1000' and everything is fine, correct response is coming from server, there is no error in Console, but in Chrome Network request-url is to localhost:3000/.../...

if I sent wrong data to server, it's coming correct error and bad request error in Console

can someone help me, thanks

It sounds like your React app is making requests to the wrong URL. Based on the information you provided, it appears that your React app is running on localhost:3000 and your Node.js server is running on localhost:1000 , but your requests are being sent to localhost:3000 .

To fix this issue, you will need to update your React app to send requests to the correct URL, which should be http://localhost:1000/auth/sign/in . This can typically be done by updating the base URL or endpoint for your API requests in your React app.

For example, if you are using the fetch API to make requests in your React app, you can update the base URL for your requests by setting the baseURL property in your fetch options:

 fetch('/auth/sign/in', { baseURL: 'http://localhost:1000', // Other fetch options })

Or, if you are using a library such as Axios to make requests in your React app, you can update the base URL for your requests by setting the baseURL property in the Axios configuration:

 import axios from 'axios'; axios.defaults.baseURL = 'http://localhost:1000';

After updating the base URL for your API requests, your React app should send requests to the correct URL, http://localhost:1000/auth/sign/in , and you should no longer see requests being sent to localhost:3000 in the Chrome Network tab.

It's worth noting that the exact solution for updating the base URL for your API requests will depend on the specific details of your React app and how you are making requests to your server. If you are having trouble updating the base URL, you may want to consult the documentation for the specific library or API you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM