rack-naked-to-www 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +65 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/lib/rack/naked-to-www.rb +42 -0
- data/lib/rack-naked-to-www.rb +1 -0
- data/rack-naked-to-www.gemspec +31 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc0108ba12531ee29fd0169a35ce5bf1242ad7f42d0bdef48a755d2bb977c9d8
|
4
|
+
data.tar.gz: 6e4e39e8b0cdc839cc880733305c50d0017a976fccf926cf092a5d722774e7a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32b4c258c96e5c266d218c557245266a7960c7d27dc32e6ef3b2cec860b9237213ebb0647c08e90fbd5190e803a87c05f60fbbe2f51bff62659f193270911507
|
7
|
+
data.tar.gz: 67dc6652820b86814cca8ceadb1e1395473b651bb442d9a06860f8b132693c104e9188143fa03ab64ef9f071ce411844c986f44db0defc5be9546e9807f4cadb
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rack-naked-to-www (0.1.0)
|
5
|
+
rack
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
json (2.6.2)
|
13
|
+
parallel (1.22.1)
|
14
|
+
parser (3.1.2.1)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rack (2.2.4)
|
17
|
+
rainbow (3.1.1)
|
18
|
+
rake (13.0.6)
|
19
|
+
regexp_parser (2.6.0)
|
20
|
+
rexml (3.2.5)
|
21
|
+
rspec (3.11.0)
|
22
|
+
rspec-core (~> 3.11.0)
|
23
|
+
rspec-expectations (~> 3.11.0)
|
24
|
+
rspec-mocks (~> 3.11.0)
|
25
|
+
rspec-core (3.11.0)
|
26
|
+
rspec-support (~> 3.11.0)
|
27
|
+
rspec-expectations (3.11.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-mocks (3.11.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.11.0)
|
33
|
+
rspec-support (3.11.1)
|
34
|
+
rubocop (1.35.1)
|
35
|
+
json (~> 2.3)
|
36
|
+
parallel (~> 1.10)
|
37
|
+
parser (>= 3.1.2.1)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
regexp_parser (>= 1.8, < 3.0)
|
40
|
+
rexml (>= 3.2.5, < 4.0)
|
41
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
42
|
+
ruby-progressbar (~> 1.7)
|
43
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
44
|
+
rubocop-ast (1.21.0)
|
45
|
+
parser (>= 3.1.1.0)
|
46
|
+
rubocop-performance (1.14.3)
|
47
|
+
rubocop (>= 1.7.0, < 2.0)
|
48
|
+
rubocop-ast (>= 0.4.0)
|
49
|
+
ruby-progressbar (1.11.0)
|
50
|
+
standard (1.16.1)
|
51
|
+
rubocop (= 1.35.1)
|
52
|
+
rubocop-performance (= 1.14.3)
|
53
|
+
unicode-display_width (2.3.0)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
rack-naked-to-www!
|
60
|
+
rake (~> 13.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
standard (~> 1.3)
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
2.3.22
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Scott Motte
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Rack::Naked::To::Www
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
Add to your Gemfile
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem "rack-www-enforcer"
|
9
|
+
```
|
10
|
+
|
11
|
+
Add to `config/application.rb`
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
module YourApp
|
15
|
+
class Application < Rails::Application
|
16
|
+
..
|
17
|
+
|
18
|
+
config.middleware.insert_before ActionDispatch::Static, Rack::NakedToWww
|
19
|
+
|
20
|
+
..
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
```
|
28
|
+
bundle exec rspec
|
29
|
+
bundle exec standardrb --fix
|
30
|
+
```
|
31
|
+
|
32
|
+
## Credits
|
33
|
+
|
34
|
+
Inspiration [rack-www-enforcer](https://github.com/guilleiguaran/rack-www-enforcer)
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack"
|
4
|
+
require "rack/request"
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
class NakedToWww
|
8
|
+
VERSION = "0.1.0"
|
9
|
+
|
10
|
+
def initialize(app)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if naked?(env)
|
16
|
+
redirect_to_www(env)
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def naked?(env)
|
25
|
+
return false if env["HTTP_HOST"].nil?
|
26
|
+
return false if /^localhost/.match?(env["HTTP_HOST"])
|
27
|
+
|
28
|
+
env["HTTP_HOST"].split(".").length <= 2
|
29
|
+
end
|
30
|
+
|
31
|
+
def redirect_to_www(env)
|
32
|
+
req = Request.new(env)
|
33
|
+
|
34
|
+
url = URI(req.url)
|
35
|
+
url.host = "www.#{url.host}"
|
36
|
+
|
37
|
+
headers = {"Content-Type" => "text/html", "Location" => url.to_s}
|
38
|
+
|
39
|
+
[302, headers, []]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "rack/naked-to-www"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rack/naked-to-www"
|
4
|
+
|
5
|
+
Gem::Specification.new "rack-naked-to-www" do |spec|
|
6
|
+
spec.name = "rack-naked-to-www"
|
7
|
+
spec.version = Rack::NakedToWww::VERSION
|
8
|
+
spec.authors = ["motdotla"]
|
9
|
+
spec.email = ["mot@mot.la"]
|
10
|
+
|
11
|
+
spec.summary = "rack-naked-to-www"
|
12
|
+
spec.description = "Redirect naked domain to www"
|
13
|
+
spec.homepage = "https://github.com/dotenv-org/rack-naked-to-www"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.3.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/dotenv-org/rack-naked-to-www"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/dotenv-org/rack-naked-to-www"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "rack"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-naked-to-www
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- motdotla
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Redirect naked domain to www
|
28
|
+
email:
|
29
|
+
- mot@mot.la
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".standard.yml"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/rack-naked-to-www.rb
|
43
|
+
- lib/rack/naked-to-www.rb
|
44
|
+
- rack-naked-to-www.gemspec
|
45
|
+
homepage: https://github.com/dotenv-org/rack-naked-to-www
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://github.com/dotenv-org/rack-naked-to-www
|
50
|
+
source_code_uri: https://github.com/dotenv-org/rack-naked-to-www
|
51
|
+
changelog_uri: https://github.com/dotenv-org/rack-naked-to-www
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.3.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.1.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: rack-naked-to-www
|
71
|
+
test_files: []
|