puma-ngrok-tunnel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +62 -20
- data/lib/puma-ngrok-tunnel/version.rb +1 -1
- data/lib/puma/plugin/ngrok_tunnel.rb +14 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d029d8c4cf8dc072229ec171cc0efb786336832b35244c077706aab670297f5b
|
4
|
+
data.tar.gz: 2be2b3c9fb277c079d0f74183805703505fff780fc60b27fba90d0ac189f8f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac0f89bbd524854feae311cac699a33d74e6e2459c88b9886afc786c069b0fe58efe322f86480efba2082bf5e6e0d6263ae6c04a6c1bf4372535d29b67f57d98
|
7
|
+
data.tar.gz: dad8c33285f788cf5d7745c25bce721b62665efadb704b1fb9bfa4d03064870776df087cb7ce23c94cc3d76c69a0e08d17ee208b6d6f9feaef62aa657bdab4dd
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.1.1
|
4
|
+
|
5
|
+
* Improving mechanism for the tunnel being closed when rails is restarted, namely when `touch tmp/restart.txt` is used. This is based on https://github.com/harmjanblok/puma-metrics/blob/master/lib/puma/plugin/metrics.rb
|
6
|
+
* Adding more examples to docs.
|
7
|
+
|
8
|
+
## 0.1.0
|
9
|
+
|
10
|
+
* Initial Release
|
data/README.md
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
# puma-ngrok-tunnel
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/puma-ngrok-tunnel.svg)](https://badge.fury.io/rb/puma-ngrok-tunnel)
|
4
4
|
|
5
|
+
![image](https://user-images.githubusercontent.com/325384/57193363-1d2c4800-6f32-11e9-82a4-1efc54fac0ad.png)
|
6
|
+
|
7
|
+
A plugin for puma that'll start a [ngrok tunnel](https://ngrok.com/) to your rails server when puma starts. Primary I built this to make the following a little easier:
|
8
|
+
|
9
|
+
* Working with apps that require Webhooks to be received by the app to work correctly
|
10
|
+
* Demoing your local rails app to someone else without have to share IPs
|
11
|
+
* Working with [Puma-dev](https://github.com/puma/puma-dev/) so your apps feels as production-like as possible.
|
12
|
+
* Testing on mobile.
|
13
|
+
|
14
|
+
I've setup a [sample Rails 6 app](https://github.com/MikeRogers0/puma-ngrok-tunnel-SampleRails6App) that demos an implementation of this gem.
|
5
15
|
|
6
16
|
## Installation
|
7
17
|
|
@@ -25,15 +35,7 @@ Lastly in your `config/puma.rb` file, append the line:
|
|
25
35
|
|
26
36
|
|
27
37
|
```ruby
|
28
|
-
plugin :ngrok_tunnel if ENV
|
29
|
-
```
|
30
|
-
|
31
|
-
## Installation with puma-dev
|
32
|
-
|
33
|
-
Add the environmental variable (in a .env file for example):
|
34
|
-
|
35
|
-
```
|
36
|
-
CONFIG=config/puma.rb
|
38
|
+
plugin :ngrok_tunnel if ENV.fetch('RAILS_ENV') { 'development' } == 'development'
|
37
39
|
```
|
38
40
|
|
39
41
|
## Usage
|
@@ -42,16 +44,26 @@ Read about how to configure puma to use this plugin here: https://github.com/pum
|
|
42
44
|
|
43
45
|
There are a few variables this plugin reads from the environment which control its behavior. These are based on the arguments you'd pass to the [ngrok terminal command](https://ngrok.com/docs#http-subdomain).
|
44
46
|
|
45
|
-
* `PORT` - defaults to 3000
|
46
|
-
* `NGROK_ADDR`
|
47
|
-
* `NGROK_AUTHTOKEN`
|
48
|
-
* `NGROK_HOST_HEADER`
|
49
|
-
* `NGROK_CONFIG`
|
50
|
-
* `NGROK_SUBDOMAIN`
|
51
|
-
* `NGROK_REGION`
|
52
|
-
* `NGROK_HOSTNAME` -
|
47
|
+
* `PORT` - Optional, your rails port, defaults to `3000`. If `NGROK_ADDR` is set, this is ignored.
|
48
|
+
* `NGROK_ADDR` - Optional, if you're using Puma-dev set this to be your hostname & port, e.g. `my-app-name.test:443`.
|
49
|
+
* `NGROK_AUTHTOKEN` - Optional, your ngrok authtoken. If you have ngrok configured on your local machine you don't need this.
|
50
|
+
* `NGROK_HOST_HEADER` - Optional, if you're using Puma-dev you should set this to your virtual host e.g. `my-app-name.test`.
|
51
|
+
* `NGROK_CONFIG` - Optional, your ngrok configuration file location, defaults to `~/.ngrok2/ngrok.yml`.
|
52
|
+
* `NGROK_SUBDOMAIN` - Optional, ngrok will assign you a random subdomain unless this is set.
|
53
|
+
* `NGROK_REGION` - Optional, the region of your ngrok tunnel. defaults to `us`.
|
54
|
+
* `NGROK_HOSTNAME` - Optional, full ngrok hostname, shouldn't be set if `NGROK_SUBDOMAIN` is set.
|
55
|
+
|
56
|
+
### Sample .env for use with `rails s`
|
57
|
+
|
58
|
+
```
|
59
|
+
# puma-ngrok-tunnel setup
|
60
|
+
# You need https://github.com/bkeepers/dotenv setup to make sure Puma can use these.
|
61
|
+
export NGROK_TUNNEL_ENABLED=true
|
62
|
+
export NGROK_SUBDOMAIN=my-app-name
|
63
|
+
export NGROK_REGION=eu
|
64
|
+
```
|
53
65
|
|
54
|
-
### Sample .env
|
66
|
+
### Sample .env for use with Puma-dev
|
55
67
|
|
56
68
|
```
|
57
69
|
# Puma-dev: You need to define this otherwise it uses it's own puma.rb file.
|
@@ -59,7 +71,6 @@ CONFIG=config/puma.rb
|
|
59
71
|
|
60
72
|
# puma-ngrok-tunnel setup
|
61
73
|
# These should start with 'export' otherwise puma-dev won't use them.
|
62
|
-
export NGROK_TUNNEL_ENABLED=true
|
63
74
|
export NGROK_SUBDOMAIN=my-app-name
|
64
75
|
export NGROK_REGION=eu
|
65
76
|
# The URL (and HTTPS Port) you might use to access this under Puma-dev
|
@@ -67,6 +78,37 @@ export NGROK_ADDR=my-app-name.test:443
|
|
67
78
|
export NGROK_HOST_HEADER=my-app-name.test
|
68
79
|
```
|
69
80
|
|
81
|
+
## Pitfalls & solutions
|
82
|
+
|
83
|
+
### ngrok tunnel not always stopping when puma-dev stops
|
84
|
+
|
85
|
+
If you see an error saying `http: proxy error: dial unix`, it means ngrok was able to stop when puma was stopped. Right now the solution is to run:
|
86
|
+
|
87
|
+
$ pkill ngrok
|
88
|
+
|
89
|
+
in your terminal.
|
90
|
+
|
91
|
+
### Rails 6 "Blocked host" error
|
92
|
+
|
93
|
+
If you seeing an error like:
|
94
|
+
|
95
|
+
```
|
96
|
+
Blocked host: a620ba29.ngrok.io
|
97
|
+
To allow requests to a620ba29.ngrok.io, add the following to your environment configuration:
|
98
|
+
config.hosts << "a620ba29.ngrok.io"
|
99
|
+
```
|
100
|
+
|
101
|
+
Open your `config/environments/development.rb` file add add:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# Whitelist ngrok connections to development enviroment.
|
105
|
+
config.hosts << /[a-z0-9]+\.ngrok\.io/
|
106
|
+
# Whitelist Puma-Dev hostname.
|
107
|
+
config.hosts << 'samplerailsapp.test'
|
108
|
+
config.hosts << /[a-z0-9]+\.samplerailsapp.test/
|
109
|
+
```
|
110
|
+
|
111
|
+
This will whitelist the ngrok subdomain to access your rails host.
|
70
112
|
|
71
113
|
## License
|
72
114
|
|
@@ -1,11 +1,20 @@
|
|
1
|
-
require 'ngrok/tunnel'
|
2
1
|
|
3
2
|
Puma::Plugin.create do
|
4
|
-
def start(
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def start(launcher)
|
4
|
+
puts '[puma-ngrok-tunnel] Starting'
|
5
|
+
|
6
|
+
require 'ngrok/tunnel'
|
7
|
+
|
8
|
+
launcher.events.register(:state) do |state|
|
9
|
+
if %i[halt restart stop].include?(state)
|
10
|
+
if Ngrok::Tunnel.running?
|
11
|
+
puts '[puma-ngrok-tunnel] Stopping'
|
12
|
+
Ngrok::Tunnel.stop
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
16
|
+
|
17
|
+
puts '[puma-ngrok-tunnel] Tunneling at: ' + Ngrok::Tunnel.start(options)
|
9
18
|
end
|
10
19
|
|
11
20
|
def options
|
@@ -20,8 +29,3 @@ Puma::Plugin.create do
|
|
20
29
|
}.reject { |_, value| value.nil? }
|
21
30
|
end
|
22
31
|
end
|
23
|
-
|
24
|
-
at_exit do
|
25
|
-
puts '[puma-ngrok-tunnel] Stopping'
|
26
|
-
Ngrok::Tunnel.stop
|
27
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-ngrok-tunnel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Rogers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ngrok-tunnel
|
@@ -81,6 +81,7 @@ extra_rdoc_files: []
|
|
81
81
|
files:
|
82
82
|
- ".gitignore"
|
83
83
|
- ".travis.yml"
|
84
|
+
- CHANGELOG.md
|
84
85
|
- Gemfile
|
85
86
|
- LICENSE.txt
|
86
87
|
- README.md
|