Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web_allow_hosts to the config #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/ngrok/tunnel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class << self
attr_reader :pid, :ngrok_url, :ngrok_url_https, :status

def init(params = {})
@params = {addr: 3001, timeout: 10, config: create_empty_config_file.path}.merge(params)
allow_hosts = params[:allow_hosts] || []
@params = {addr: 3001, timeout: 10, config: create_empty_config_file(allow_hosts).path}.merge(params)
@status = :stopped unless @status
end

Expand Down Expand Up @@ -128,12 +129,15 @@ def pre_v3?
/^ngrok version [012]\./.match?(@version)
end

def create_empty_config_file
def create_empty_config_file(allow_hosts)
tmp = Tempfile.new('ngrok_config-')
tmp << "version: ""2""\n"
if allow_hosts.any?
tmp << "web_allow_hosts:\n"
allow_hosts.each {|host| tmp << " - #{host}\n"}
end
tmp.flush
tmp.close

tmp
end
end
Expand Down