We love designing and developing websites, but what really drives us is solving problems and cultivating strong relationships with our clients
Testing webhooks in development platforms
By : Javed
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
Comments
Reactions
Testing webhooks with local development platforms http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/
RT@shabda: Testing webhooks with local development platforms http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/
http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/ How to test webhooks with your local development system.
RT@agiliqdotcom: http://agiliq.com/blog/2010/09/testing-webhooks-in-development-platforms/ How to test webhooks with your local development system.
- Deploying Django apps on Heroku
- Deploy Django App in 5 Easy Steps
- Project Management Tools for Start-Ups
- Generating a pdf from an image using PIL and django
- Dynamically attaching SITE_ID to Django Caching
- Screencast: How to deploy Django on Heroku
- Deploying Django apps on Heroku
- How to use pep8.py to write better Django code
- Screencast: Django Tutorial Part 1
- How and why to use pyflakes to write better Python
- rails
- django
- linkroundup
- django opinion
- opinion
- business
- API
- appengine
- python
- satire
- startup
- Uncategorized
- marketing
- personal
- rambling
- search
- interviews
- seo-interviews
- 5startupideas
- ideas
- seo
- tips
- forms
- paypal
- utilities
- datetime
- web2.0
- Amazon
- algorithms
- presentations
- products
- pinax
- satchmo
- ecommerce
- microsoft
- yahoo
- book
- tutorial
- models
- aggreagtion
- meta
- India
- apps
- about
- CSS
- Design
- wordpress
- test slug
- vim
- urls
- reviews
- javascript
- xmpp
- emacs
- Typography
- Grid Theory
- Color Theory
- iphone
- android
- titanium
- mobile applications
- CSS3
- Browser Compatibility
- mobile
- jobs
- lamson
- django setup
- files
- upload
- jsTree
- hierarchical view
- web page
- Treeview
- coffeescript
- request
- response
- South
- django south
- django migration
- --fake
- screencasts
- django caching
- SITE_ID prefix
- review
- code hosting
- comparison
- unfuddle
- fogbugz
- assembla
- github
- project management
- ticketing system
- gunicorn
- deploy
- nginx
- ubuntu
- vps
- April 2012
- February 2012
- January 2012
- December 2011
- October 2011
- September 2011
- July 2011
- June 2011
- April 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- June 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- November 2008
- October 2008
- June 2008
- May 2008
- April 2008
Alternatively, you can just use localtunnel.