Webhooks local testing

Hi Specklers,

I’ve been attempting to play around with webhooks by creating a local endpoint. ( Using a tunneling service like ngrok is off the table for now, as I’ll need the IT to whitelist the endpoint.)

However, im getting this error…

Error: Local network requests are not allowed. To allow use ALLOW_LOCAL_NETWORK=true environment variable

Question:
Where should i be setting this environment variable ?? I’m using a local deployment of the given docker-compose file.

Thanks alot
Han

@gjedlicska / @iainsproat will correct me if I’m wrong, but I believe this should go under the webhook-service's service part in the docker file, something like:

PS: https://webhook.site/ was a god send when testing hooks out! (might not be applicable to what you need, but you never know!)

1 Like

That looks right @dimitrie , the docker compose will set the environment variable and it should be picked up by the webhook service when it runs.

1 Like

@dimitrie @iainsproat Thanks for checking this out guys. Howeve, now I’m getting another error. I have my endpoint running, and hook set on localhost:5001.

Any clue why is it trying to connect to 127.0.0.1:5001?
image

thanks again :slight_smile: ,
Han

127.0.0.1 is the IP address associated with localhost, so that part looks ok. localhost - Wikipedia

Can you access localhost:5001/api/convert/reverse (or 127.0.0.1:5001/api/convert/reverse) from your browser?

I see, thanks for sharing !
I can access it on postman, but not on the browser.
Is that different ?

Hey Han,

your browser is trying to use the GET method of the endpoint, if your server only provides a POST method, it wont respond successfully for browser requests. However if it works with postman, that should be good for the webhook service.

I see you are using https for the localhost url, maybe that could cause an issue here. Could you try with plain http?

1 Like

Yes, as @gjedlicska said, the HTTP ERROR 405 is expected in the browser as it uses a GET http method and not a POST. It shows it can connect to the server, as does the Postman request which correctly uses POST. :+1:

hello @gjedlicska ,

Tried with plain http, am still getting the ECONREFUSED error.

Really appreciate the help guys :slight_smile:

Works with postman again tho.

Not sure if this helps, but this is the route on ASP.Net

  [HttpPost]
  public ActionResult Post()
  {
      Console.Write( "Triggering hook..." );
      return NoContent();
  }

So if your services are running in docker with docker-compose, the meaning of localhost is a bit different, than if you are running bare metal on the host OS. In this case, the webhook service container localhost is being asked to serve the request, which doesn’t have anything running on port 5000.

See a bit wider explanation and some possible solutions here:

If the service you are developing runs in a docker container, you can connect to the same docker network, and use its service name instead of localhost or ip.

2 Likes

Hey @gjedlicska,

Thanks for the explanation !

However, only my speckle server is running in a local docker container, my services are still running on localhost.

The scenario you described seem like it applies only if all my services on deployed in a container, am i right to say that ?

Hi Han, this applies to any connections to localhost on the host network (i.e. your local machine) that the Speckle containers running via docker-compose might try to make.

1 Like

A quick check as to whether a single container running in Docker can reach localhost is to run the following:

docker run --rm alpine/curl:3.14 -fsSL https://localhost:5001/api/convert/reverse

As the article suggests, you may have to add the --network=host flag to this to make it work, the equivalent in docker-compose is to add network_mode: host to the yaml file.

1 Like

Exactly, in the current setup, where the webhook service has to talk to your handler, the webhook service is the client and your locally developed service is the server. So the Speckle webhook service needs to be able to find its way to your localhost server.

Since the Speckle containers are running in the confined docker environment they use a different network interface, than your server running on localhost.

To get around the issue (should only do this in local testing only) you can put your containers running in docker onto the same network as the host is. To do so, you need to add the network_mode: host config to your Speckle docker-compose.yaml

Once you do so and restart your speckle services, you should be able to access http://localhost:3000/graphql?query={serverInfo{version}} from a browser. If that works, the webhook service should be able to connect to your service running on localhost

Hope this fixes is and clarifies stuff :slight_smile:

2 Likes

Thanks @gjedlicska @iainsproat, ill attempt this again and report back ! Thank you very much for your help :slight_smile:

4 Likes