I'm a big newbie when it comes to JS and web apps. I have two servers running on my computer on two different ports (5000 and 5001). The 5000 server provides a route that needs to communicate with the server on port 5001, and I can't seem to make that work.
I'm using express.js and xhr2 for the HTTP requests. There seem to be a problem with my url. Am I not supposed to look for the port at the 0.0.0.0 address ? (I have tried using the localhost one as well and it's not working).
You can find below an example of such a route. Thanks for your help !
app.get('/user', (req, res) => {
var url = "0.0.0.0:5001/user"
var XMLHttpRequest = require('xhr2')
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
console.log(url)
xhr.addEventListener('readystatechange', function() {
if (xhr.status == 200) {
res.status(200).send(xhr.responseText)
}
});
xhr.send();
})
try localhost:port or 127.0.0.1:port, maybe that works
edit: yea you forgot the schema, try "http://localhost:5001/user" or the same with https instead. (credit @Heiko Theiße)