As the title suggests, I am unable to connect to my local express server. I am using the general cors() function to allow all routes to be ‘CORS-approved.’ The code is as follows for the express app:
The schema for the remote connection is as follows:
type Fetching @remote {
foo: String
}
type Mutation {
Fetch: Fetching
@custom(http: { url: "http://localhost:4000/foo", method: "GET" })
}
I am using standard ports for the Dgraph container (8000, 8080, 9080).
Edit:
I am quite unsure where the problem lies. The error message only states the following:
Evaluation of custom field failed because external request returned an error: Get "http://localhost:4000/foo\": dial tcp 127.0.0.1:4000: connect: connection refused for field: Fetch within type: Mutation.
I’ve finally resolved it. Apparently, WSL 2 doesn’t expose the network of the distro to the host computer which is why I cannot connect to the node server. What I did was to use the IPv4 address of the computer to map the custom HTTP request URL. This solution was found on:
However, it would be much appreciated if you can provide me with some other details to mapping the WSL 2 ports onto the host computer. Thanks once again!
Edit
I also needed to expose the IPv4 of the virtual machine to the host through netsh. The solution to that can be found here:
As a side note, I’ve also found another way. Instead of mapping the ports through netsh, we can use http://host.docker.internal:<port#> to connect outside of docker as documented here: