Last Updated: February 25, 2016
·
1.401K
· ejholmes

Start localtunnel programmatically with rails s

If you're developing an app that uses third party services that need to send notifications to your app, you can easily provide access using localtunnel:

$ localtunnel 3000

But it's a pain to have to remember to run this command. Better yet, add the following to your config/application.rb

if Rails.env.development?
  tunnel = LocalTunnel::Tunnel.new(3000, nil)
  response = tunnel.register_tunnel

  # Start localtunnel in a detached process.
  Process.detach fork { tunnel.start_tunnel }

  ENV['LOCALTUNNEL'] = response['host']
end