I have a rust server running in my machine at localhost, port:4200. I am trying to make requests to this server using a JavaScript client that uses axios library.
The code when run gives the following error:
Error: connect ECONNREFUSED 127.0.0.1:4200 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
I tried rewriting the code to use fetch library. That is also returning a connection refused error.
The API is working as required when tried from Postman. The Get call is working from the browser as well. Could not find out why the connection is refused for this call when calling from JavaScript.
I have enabled CORS options in the rust server.
fn main() {
let options = rocket_cors::Cors::default();
rocket::ignite()
.mount("/", routes![index, sign, generate])
.attach(options)
.launch();
}
EDIT:
client code that is giving above error when run from my machine:
const fetch = require("node-fetch");
var requestOptions = {
method: "GET",
headers: { "Content-Type": "application/json" }
};
fetch("http://localhost:4200/createOffer/1/license", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
browser request that is working from my machine: http://localhost:4200/createOffer/1/license