Javed
Comments
Reactions

Testing webhooks in development platforms

By : Javed Khan

Webhooks were popularized by PayPal and have become commonplace now a days. A typical webhook service fires a POST to a URL of your choice whenever something interesting happens. You handle this request and respond accordingly.

But you need to test webhooks regularly during development and it is a bit of a problem if your development server is inaccessible from the rest of the Internet. I have tried to solve this using ssh and nginx.

For this method to work you need:

  • Development server (which can hopefully process the webhook at /webhook) lets call it (D)
  • SSH accessible server (S)
  • nginx to be installed on the (S)

We will ssh into the server with a 'backdoor' that will forward connections from (S) to (D). This is also called reverse port forward. On (D)

ssh -R 8888:localhost:80 user@(S)

See man ssh for details

Here we are telling ssh to create an incoming port (8888) on (S) and forward them to (D):80. So if you access localhost:8888 on (S), ssh will call (D):80 and return the response from (D). Note that you can only call localhost:8888 from (S) right now, because the port 8888 SSH creates does not listen on the public address. This means that calling (S):8888 from the internet will fail. Now, we need to forward webhook calls to localhost:8888 (on (S)). Yo Dawg!

Enter ngnix:

nginx is a reverse proxy that can listen to calls from public address and forward them to local ports. Now we can listen to the webhook on (S) and forward the request to localhost:8888. Here's how: On (S)

location /webhook {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:8888/webhook;
}

this part lets nginx know that webhook requests should be forwarded to localhost:8888. What is localhost:8888? Oh yes, its the backdoor to (D):80 that SSH created.

The result:

  • Webhook provider calls (S)/webhook.
  • nginx receives /webhook and forwards to localhost:8888/webhook
  • ssh receives localhost:8888/webhook and forwards to (D):80/webhook
  • Inception!

tl;dr

http://public_server/webhook ==nginx=> http://localhost:8888/webhook =ssh==> http://dev_server:80/webhook



Can we help you build amazing apps? Contact us today.

Comments

Jeff Lindsay

Alternatively, you can just use localtunnel.

commmenttor
Vinay

I created http://www.ultrahook.com which solves this problem without requiring SSH. All you need is a ruby environment and ability to make HTTP requests :)

commmenttor

Reactions

shabda

Testing webhooks with local development platforms http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/

commmenttor
ashok_raavi

RT@shabda: Testing webhooks with local development platforms http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/

commmenttor
agiliqdotcom

http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/ How to test webhooks with your local development system.

commmenttor
becomingGuru

RT@agiliqdotcom: http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/ How to test webhooks with your local development system.

commmenttor
Post a comment Name :

Email :

Your site url:

Comment :

© Agiliq, 2009-2012