Skip to content

Using localtunnel with Apache Virtual Hosts and SSL

As part of the ongoing development of Leavetrack, the easiest way to track employees’ holiday and other absences, I’ve been working on integrating Twilio so that users can receive notifications via text message and approve requests via text message.

Part of this requires routing incoming text messages to my local development environment. There are a number of services that can expose localhost to the world but I chose localtunnel, which an engineer at Twilio created.

A lot of the example cases are based on running Rails default server which operates on port 3000. For my purposes however I have a named virtual host (leavetrack.local) which makes it easy to work with SSL in development and subdomains, both of which are key for my application. In order to get localtunnel to work in my environment, I did the following:

1. Configured httpd.conf to serve Leavetrack as the DocumentRoot:

DocumentRoot "/Users/robinjfisher/Code/leavetrack/public"

2. Defined a virtual host in my httpd-vhosts.conf file listening on port 80. To date my application worked entirely under SSL using mod_rewrite. However, this rewrite was causing the parameters to be dropped so I added a rewrite condition to cancel the redirect where the URL is that defined for incoming messages:


  ServerName leavetrack.local
  ServerAlias *.leavetrack.local
  RackEnv development
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteCond %{REQUEST_URI} !^/sms$
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  RewriteLogLevel 2
  RewriteLog "/var/log/apache2/rewrite.log"

3. In my Rails application, I exposed a route at /sms which pointed to the create action of the Messages Controller. In my Twilio dashboard, I then pointed the SMS Request URL to the localtunnel address with /sms appended.

Now, when I send a text message to my Twilio number, it is routed to my local machine at which the create action in my Messages Controller parses the content and creates the corresponding message in the database.

 

One Comment Post a comment
  1. Reblogged this on Sutoprise Avenue, A SutoCom Source.

    March 1, 2013

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 169 other followers