class Object

Public Instance Methods

ngrok_start!() click to toggle source
# File lib/puma/plugin/ngrok_tunnel.rb, line 16
def ngrok_start!
  puts "[puma-ngrok-tunnel] Tunneling at: #{Ngrok::Tunnel.start(options)}"
rescue Ngrok::FetchUrlError => e
  puts "[puma-ngrok-tunnel] Unable connect to ngrok server (You might be offline): #{e}"
rescue Ngrok::Error => e
  puts "[puma-ngrok-tunnel] Unable to start tunnel (You might have another active connection): #{e}"
end
ngrok_stop!() click to toggle source
# File lib/puma/plugin/ngrok_tunnel.rb, line 24
def ngrok_stop!
  return unless Ngrok::Tunnel.running?

  puts '[puma-ngrok-tunnel] Stopping'
  Ngrok::Tunnel.stop
end
options() click to toggle source
# File lib/puma/plugin/ngrok_tunnel.rb, line 31
def options
  @options ||= {
    addr: ENV.fetch('NGROK_ADDR', nil) || ENV.fetch('PORT', 3000),
    authtoken: ENV.fetch('NGROK_AUTHTOKEN', nil),
    host_header: ENV.fetch('NGROK_HOST_HEADER', nil),
    config: ENV.fetch('NGROK_CONFIG') { File.join(ENV['HOME'], '.ngrok2', 'ngrok.yml') },
    subdomain: ENV.fetch('NGROK_SUBDOMAIN', nil),
    region: ENV.fetch('NGROK_REGION', nil),
    hostname: ENV.fetch('NGROK_HOSTNAME', nil)
  }.reject { |_, value| value.nil? }
end
start(launcher) click to toggle source
# File lib/puma/plugin/ngrok_tunnel.rb, line 4
def start(launcher)
  puts '[puma-ngrok-tunnel] Starting'

  launcher.events.register(:state) do |state|
    ngrok_stop! if %i[halt restart stop].include?(state)
  end

  ngrok_start!
end