Socket
Book a DemoInstallSign in
Socket

ensure_ngrok_tunnel

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ensure_ngrok_tunnel

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

EnsureNgrokTunnel

Installation

Add this line to your application's Gemfile:

gem 'ensure_ngrok_tunnel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ensure_ngrok_tunnel

Usage

In your development.rb, call EnsureNgrokTunnel.start with a valid ngrok config. If you have tunnels defined in your global ngrok config, this could just be {name: 'name-of-my-tunnel'}.

To determine whether the tunnel already exists, EnsureNgrokTunnel just looks for any tunnel bound to the port specified by addr in the config, or if not set, in ENV['PORT']. If you are using a config that just specifies a tunnel by name, you can optionally pass the port as port: XXXX.

If an instance of ngrok is already running on the standard port (4040), EnsureNgrokTunnel will talk to it, otherwise it spawns one with ngrok start --none (this instance should die when the parent process does, though with rails development the usual spring/fs-watch shenanigans will probably occasionally result in zombied ngroks).

EnsureNgrokTunnel returns the tunnel url.

Example:

  server_port = ENV.fetch('TUNNEL_PORT')
  ngrok_url = EnsureNgrokTunnel.start(
    config: {
      name: Rails.application.class.parent.name.underscore,
      addr: server_port,
      proto: 'tls',
      hostname: ENV.fetch('API_DOMAIN'),
      key: Rails.root.join('certificates', 'development-key.pem').to_s,
      crt: Rails.root.join('certificates', 'development-cert.pem').to_s
    },
    port: server_port
  )

  puts "[NGROK] tunneling at " + ngrok_url

NOTE: be careful about using the standard PORT env var in Rails with sidekiq. When using heroku local & a Procfile with web & worker processes, the PORT variable seems to get incremented by 100 in the worker process, which will cause EnsureNgrokTunnel not to find the tunnel in whichever is the second process to launch.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/lastobelus/ensure_ngrok_tunnel.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 25 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.