rails-nginx 1.0.0.pre.beta.5 → 1.0.0.pre.beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -18
- data/lib/puma/plugin/rails_nginx.rb +1 -0
- data/lib/rails/nginx/configuration.rb +45 -0
- data/lib/rails/nginx/version.rb +1 -1
- data/lib/rails/nginx.rb +13 -27
- 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: '058189602280cfeeb47c1b5559b6f46be3ec9e28ae16cc14414a621c3a549b05'
|
4
|
+
data.tar.gz: 2fa39064a2fb2980faf7c637a66fca8dfb20ea6670ad5b4868a69006460a6f79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2219d85b6fd63d594f2d12c33a18e5317b33b216cfc0531e67f4704c31967a347c4b1bb1951a33636a82bcec5a6109d9a707df440909f07cc716d74698a1dea2
|
7
|
+
data.tar.gz: 538294ecdf66eb548a36849242b2be90baa67736d311d6f3764c294e15b5464c6c843b834dfb4e70b84b8a6facf066d0558fe4efbcf983e7f7127cc6529a569c
|
data/README.md
CHANGED
@@ -67,32 +67,31 @@ gem install rails-nginx
|
|
67
67
|
|
68
68
|
Add the Puma plugin to your configuration, and limit it to your development environment.
|
69
69
|
|
70
|
-
**config/puma.rb**
|
70
|
+
**File: config/puma.rb**
|
71
71
|
```ruby
|
72
72
|
plugin :rails_nginx if Rails.env.development?
|
73
73
|
```
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
>
|
80
|
-
|
75
|
+
Then simply start Rails!
|
76
|
+
|
77
|
+
**Terminal**
|
78
|
+
```
|
79
|
+
> ./bin/rails
|
80
|
+
```
|
81
|
+
|
82
|
+
OR
|
83
|
+
|
84
|
+
```
|
85
|
+
> ./bin/rails -p 3001
|
86
|
+
```
|
87
|
+
|
88
|
+
> [!NOTE]
|
89
|
+
> Rails NGINX will clear all port bindings and assign back to Puma a random open port, or the provided Rails port parameter.
|
81
90
|
>
|
82
|
-
> **
|
91
|
+
> The following Puma configuration will be **ignored**.
|
83
92
|
> ```ruby
|
84
93
|
> port ENV.fetch("PORT") { 3000 }
|
85
94
|
> ```
|
86
|
-
>
|
87
|
-
> OR simply disable it in your development environment:
|
88
|
-
> ```ruby
|
89
|
-
> port ENV.fetch("PORT") { 3000 } unless Rails.env.development?
|
90
|
-
> ```
|
91
|
-
>
|
92
|
-
> OR always manually provide an open port when starting Rails:
|
93
|
-
> ```
|
94
|
-
> ./bin/rails server -p 3001
|
95
|
-
> ```
|
96
95
|
|
97
96
|
### Default Configuration
|
98
97
|
By default, Rails NGINX will configure [Ruby NGINX](https://github.com/bert-mccutchen/ruby-nginx) with the following options. For the examples, pretend I have an application called "HelloWorld".
|
@@ -108,6 +107,9 @@ By default, Rails NGINX will configure [Ruby NGINX](https://github.com/bert-mccu
|
|
108
107
|
| `ssl_certificate_key_path` | `Rails.root` + `tmp/nginx/_[DOMAIN]-key.pem` | `/home/bert/hello_world/tmp/nginx/_hello-world.test-key.pem` |
|
109
108
|
| `access_log_path` | `Rails.root` + `log/nginx/[DOMAIN].access.log` | `/home/bert/hello_world/log/hello-world.test.access.log` |
|
110
109
|
| `error_log_path` | `Rails.root` + `log/nginx/[DOMAIN].error.log` | `/home/bert/hello_world/log/hello-world.test.error.log` |
|
110
|
+
| `skip_teardown`* | `false` | |
|
111
|
+
|
112
|
+
\* Skipping teardown simply leaves the NGINX configuration and hosts mapping in place. This can be useful if you require elevated permissions to change the hosts file, and you don't want to be asked to enter your credentials every time. Any attempts to visit the server's domain while the server is offline will result in a NGINX error page.
|
111
113
|
|
112
114
|
### Advanced Usage
|
113
115
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Nginx
|
5
|
+
class Configuration
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options if rails_server?
|
8
|
+
end
|
9
|
+
|
10
|
+
def rails_server?
|
11
|
+
defined?(Rails::Server)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown?
|
15
|
+
!@options[:skip_teardown]
|
16
|
+
end
|
17
|
+
|
18
|
+
def nginx_options
|
19
|
+
defaults.merge(@options).except(:skip_teardown)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def domain
|
25
|
+
@options[:domain] || "#{Rails.application.class.module_parent.name.underscore.dasherize}.test"
|
26
|
+
end
|
27
|
+
|
28
|
+
def defaults
|
29
|
+
{
|
30
|
+
domain: domain,
|
31
|
+
port: ENV["PORT"],
|
32
|
+
root_path: Rails.public_path,
|
33
|
+
template_path: File.expand_path("templates/nginx.conf.erb", __dir__),
|
34
|
+
ssl: true,
|
35
|
+
log: true,
|
36
|
+
ssl_certificate_path: Rails.root.join("tmp/nginx/_#{domain}.pem"),
|
37
|
+
ssl_certificate_key_path: Rails.root.join("tmp/nginx/_#{domain}-key.pem"),
|
38
|
+
access_log_path: Rails.root.join("log/nginx/#{domain}.access.log"),
|
39
|
+
error_log_path: Rails.root.join("log/nginx/#{domain}.error.log"),
|
40
|
+
skip_teardown: false
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/rails/nginx/version.rb
CHANGED
data/lib/rails/nginx.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "socket"
|
4
4
|
require "ruby/nginx"
|
5
|
+
require_relative "nginx/configuration"
|
5
6
|
require_relative "nginx/version"
|
6
7
|
|
7
8
|
module Rails
|
@@ -13,9 +14,10 @@ module Rails
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.start!(options = {}, &block)
|
16
|
-
|
17
|
+
rails_config = Configuration.new(options)
|
18
|
+
return unless rails_config.rails_server?
|
17
19
|
|
18
|
-
config = Ruby::Nginx.add!(
|
20
|
+
config = Ruby::Nginx.add!(rails_config.nginx_options, &block)
|
19
21
|
|
20
22
|
puts start_message(config.options)
|
21
23
|
rescue Ruby::Nginx::Error => e
|
@@ -23,38 +25,17 @@ module Rails
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def self.stop!(options = {}, &block)
|
26
|
-
|
28
|
+
rails_config = Configuration.new(options)
|
29
|
+
return unless rails_config.rails_server? && rails_config.teardown?
|
27
30
|
|
28
|
-
|
31
|
+
puts stop_message(rails_config.nginx_options)
|
32
|
+
Ruby::Nginx.remove!(rails_config.nginx_options, &block)
|
29
33
|
rescue Ruby::Nginx::Error => e
|
30
34
|
abort "[Ruby::Nginx] #{e.message}"
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
34
38
|
|
35
|
-
def self.rails_server?
|
36
|
-
defined?(Rails::Server)
|
37
|
-
end
|
38
|
-
private_class_method :rails_server?
|
39
|
-
|
40
|
-
def self.defaults(options)
|
41
|
-
domain = options[:domain] || "#{Rails.application.class.module_parent.name.underscore.dasherize}.test"
|
42
|
-
|
43
|
-
{
|
44
|
-
domain: domain,
|
45
|
-
port: port,
|
46
|
-
root_path: Rails.public_path,
|
47
|
-
template_path: File.expand_path("nginx/templates/nginx.conf.erb", __dir__),
|
48
|
-
ssl: true,
|
49
|
-
log: true,
|
50
|
-
ssl_certificate_path: Rails.root.join("tmp/nginx/_#{domain}.pem"),
|
51
|
-
ssl_certificate_key_path: Rails.root.join("tmp/nginx/_#{domain}-key.pem"),
|
52
|
-
access_log_path: Rails.root.join("log/nginx/#{domain}.access.log"),
|
53
|
-
error_log_path: Rails.root.join("log/nginx/#{domain}.error.log")
|
54
|
-
}
|
55
|
-
end
|
56
|
-
private_class_method :defaults
|
57
|
-
|
58
39
|
def self.start_message(config)
|
59
40
|
message = ["* Rails NGINX version: #{Rails::Nginx::VERSION}"]
|
60
41
|
message << "* HTTP Endpoint: http://#{config[:domain]}"
|
@@ -65,5 +46,10 @@ module Rails
|
|
65
46
|
message.join("\n")
|
66
47
|
end
|
67
48
|
private_class_method :start_message
|
49
|
+
|
50
|
+
def self.stop_message(config)
|
51
|
+
"- Tearing down Rails NGINX config: #{config[:domain]}"
|
52
|
+
end
|
53
|
+
private_class_method :stop_message
|
68
54
|
end
|
69
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert McCutchen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- README.md
|
65
65
|
- lib/puma/plugin/rails_nginx.rb
|
66
66
|
- lib/rails/nginx.rb
|
67
|
+
- lib/rails/nginx/configuration.rb
|
67
68
|
- lib/rails/nginx/templates/nginx.conf.erb
|
68
69
|
- lib/rails/nginx/version.rb
|
69
70
|
homepage: https://github.com/bert-mccutchen/rails-nginx
|