Last active
October 26, 2017 08:48
-
-
Save jooeycheng/e962e567ca1527a55c953727d575634b to your computer and use it in GitHub Desktop.
Ruby auto-restart script for localtunnel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/localtunnel/localtunnel/issues/81#issuecomment-218320442 | |
# usage: ruby localtunnel.rb --port 3000 --subdomain yourdomainhere | |
require 'optparse' | |
options = { subdomain: 'defaultdomain', port: 3000 } | |
parser = OptionParser.new do |opts| | |
opts.banner = 'Usage: localtunnel.rb [options]' | |
opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain| | |
options[:subdomain] = subdomain | |
end | |
opts.on('-p', '--port port', 'Port') do |port| | |
options[:port] = port | |
end | |
opts.on('-h', '--help', 'Displays Help') do | |
puts opts | |
exit | |
end | |
end | |
parser.parse! | |
def ordinal(number) | |
abs_number = number.to_i.abs | |
if (11..13).cover?(abs_number % 100) | |
'th' | |
else | |
case abs_number % 10 | |
when 1 then 'st' | |
when 2 then 'nd' | |
when 3 then 'rd' | |
else 'th' | |
end | |
end | |
end | |
def ordinalize(number) | |
"#{number}#{ordinal(number)}" | |
end | |
launch_count = 0 | |
while true | |
launch_count += 1 | |
puts "Running localtunnel for the #{ordinalize(launch_count)} time on https://#{options[:subdomain]}.localtunnel.me, port #{options[:port]}" | |
`lt --port #{options[:port]} --subdomain #{options[:subdomain]}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment