rails-local_subdomain 1.0.9
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 +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +14 -0
- data/.ruby-gemset +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +2 -0
- data/lib/rails/local_subdomain.rb +57 -0
- data/lib/rails/local_subdomain/rack/handler.rb +41 -0
- data/lib/rails/local_subdomain/version.rb +7 -0
- data/rails-local_subdomain.gemspec +29 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: abd6e2c68158f9413a0051cb5c0123fdb2d1a16a
|
4
|
+
data.tar.gz: d4cff48ed2674d063e5e4985aff428d7e4785dd6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d49ff3c038f882f02d4cccdcf49bf0303e62063248fcfee207f7b40c9d6d78807d06d378c6f6a3b59520cf3a79799535ef93955ab1debd470bd5b7dee7d59496
|
7
|
+
data.tar.gz: 7ed32ed4e9e41838a869c212576cfc911bf0bd0af6c1a9e72b67b2520a7fb26718d9c649187cc74c1b0a544bcdb4e5c45ac5834e7487caee6d42cb155f8d6222
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Please see the following for configuration options:
|
2
|
+
# https://github.com/bbatsov/rubocop
|
3
|
+
# https://github.com/nevir/rubocop-rspec
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
|
7
|
+
Rails:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/MultilineMethodCallBraceLayout:
|
11
|
+
EnforcedStyle: same_line
|
12
|
+
|
13
|
+
Style/MultilineMethodCallIndentation:
|
14
|
+
EnforcedStyle: indented
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails-local_subdomain
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kyle Whittington
|
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,97 @@
|
|
1
|
+
# Rails::LocalSubdomain
|
2
|
+
Rails localhost subdomain support.
|
3
|
+
|
4
|
+
## Description
|
5
|
+
|
6
|
+
`Rails::LocalSubdomain` enables the developer access to routes within a
|
7
|
+
`Rails` subdomain (e.g. testing, Q.A.). It should work out of the box.
|
8
|
+
|
9
|
+
Almost all of the work was completed by https://github.com/manuelvanrijn
|
10
|
+
(https://github.com/manuelvanrijn/local-subdomain). I only
|
11
|
+
wanted to add the ability to configure which environments will have `Rails`
|
12
|
+
subdomain support. Specifically, I was trying to test a Rails application via
|
13
|
+
`Capybara` and had to modify the original gem source to let us access
|
14
|
+
subdomains during tests.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
1. Add the gem to your `Gemfile`, preferably outside of any group.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'rails-local_subdomain', group: :test # bad
|
22
|
+
|
23
|
+
gem 'rails-local_subdomain' # good
|
24
|
+
```
|
25
|
+
|
26
|
+
2. Run `bundle install`
|
27
|
+
3. Include the `Rails::LocalSubdomain` module into a controller
|
28
|
+
(usually `ApplicationController`)
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rails/local_subdomain'
|
32
|
+
|
33
|
+
class ApplicationController < ActionController::Base
|
34
|
+
include Rails::LocalSubdomain
|
35
|
+
....
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Subdomains should now be accessible in all `Rails` environments white listed in
|
40
|
+
`Rails::LocalSubdomain.enabled_environments`.
|
41
|
+
|
42
|
+
## Configuration
|
43
|
+
|
44
|
+
Configuration can be easily done via `Rails` initializers, simply monkey-patch
|
45
|
+
in whatever values you wish to customize:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# ./config/initializers/rails/local_subdomain.rb
|
49
|
+
|
50
|
+
module Rails
|
51
|
+
module LocalSubdomain
|
52
|
+
def self.enabled_environments
|
53
|
+
%w(develop test)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
## How does it work?
|
60
|
+
|
61
|
+
### Rack::Handler
|
62
|
+
|
63
|
+
`Rails::LocalSubdomain` monkey-patches `Rack::Handler` to bind to `0.0.0.0`
|
64
|
+
rather than `localhost`.
|
65
|
+
|
66
|
+
By default, this gem uses the domain [http://lvh.me](http://lvh.me) to handle
|
67
|
+
our requests for our subdomain(s). Request to the domain `lvh.me` redirects all
|
68
|
+
requests to `127.0.0.1`.
|
69
|
+
|
70
|
+
This give's us the ability to browse to
|
71
|
+
[http://subdomain.lvh.me:3000](http://subdomain.lvh.me:3000) and handle
|
72
|
+
`request.subdomain` from our controllers.
|
73
|
+
|
74
|
+
Because we're going to use the external domain [http://lvh.me](http://lvh.me)
|
75
|
+
which redirects to `127.0.0.1` we have to make our server not to bind to
|
76
|
+
`localhost` only.
|
77
|
+
|
78
|
+
### LocalSubdomain module
|
79
|
+
|
80
|
+
This module includes a `before_action` which will check if the request is
|
81
|
+
served by [http://lvh.me](http://lvh.me). If not it will redirect to the domain.
|
82
|
+
|
83
|
+
So when we browse to [http://localhost:3000](http://localhost:3000) it will
|
84
|
+
redirect you to [http://lvh.me:3000](http://lvh.me:3000)
|
85
|
+
|
86
|
+
## Supported ruby servers
|
87
|
+
|
88
|
+
I've tested the gem with:
|
89
|
+
|
90
|
+
* [WEBrick](https://rubygems.org/gems/webrick)
|
91
|
+
* [Puma](http://puma.io/)
|
92
|
+
* [Thin](http://code.macournoyer.com/thin/)
|
93
|
+
|
94
|
+
## Credits
|
95
|
+
|
96
|
+
Thanks to https://github.com/manuelvanrijn/local-subdomain for coming up with
|
97
|
+
the original gem. It's helped my development a lot!
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/local_subdomain/version'
|
3
|
+
require 'rails/local_subdomain/rack/handler'
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
# Redirects to a specified domain (or `'lvh.me'` if not provided) when Rails
|
7
|
+
# is running in an LocalSubdomain.enabled_environments environment.
|
8
|
+
module LocalSubdomain
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
before_action :redirect_to_lvh_me
|
13
|
+
end
|
14
|
+
|
15
|
+
# Should be monkey-patched to configure which Rails environments
|
16
|
+
# will have lvh.me subdomain support.
|
17
|
+
def self.enabled_environments
|
18
|
+
%w(development test)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.enabled_in?(env)
|
22
|
+
enabled_environments.include?(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def lvh_me_domain
|
26
|
+
'lvh.me'
|
27
|
+
end
|
28
|
+
|
29
|
+
def lvh_me_path
|
30
|
+
request.env['ORIGINAL_FULLPATH']
|
31
|
+
end
|
32
|
+
|
33
|
+
def lvh_me_port
|
34
|
+
request.env['SERVER_PORT']
|
35
|
+
end
|
36
|
+
|
37
|
+
def lvh_me_protocol
|
38
|
+
request.env['rack.url_scheme']
|
39
|
+
end
|
40
|
+
|
41
|
+
def lvh_me_url
|
42
|
+
"#{lvh_me_protocol}://#{lvh_me_domain}"\
|
43
|
+
"#{lvh_me_port == '80' ? '' : ':' + lvh_me_port}#{lvh_me_path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def redirect_to_lvh_me
|
47
|
+
return unless LocalSubdomain.enabled_in?(Rails.env)
|
48
|
+
return if served_by_lvh_me?
|
49
|
+
|
50
|
+
redirect_to(lvh_me_url)
|
51
|
+
end
|
52
|
+
|
53
|
+
def served_by_lvh_me?
|
54
|
+
!request.env['SERVER_NAME'][/#{lvh_me_domain}$/].nil?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'logger'
|
3
|
+
require 'rails/local_subdomain'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
# Override the Rack::Handler to bind to 0.0.0.0 which is required to support
|
7
|
+
# http://lvh.me redirects.
|
8
|
+
module Handler
|
9
|
+
class << self
|
10
|
+
alias orig_default default
|
11
|
+
end
|
12
|
+
|
13
|
+
# rubocop: disable Metrics/MethodLength
|
14
|
+
def self.default(_options = {})
|
15
|
+
orig_default.instance_eval do
|
16
|
+
class << self
|
17
|
+
alias orig_run run
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run(app, options = {})
|
21
|
+
env = (options[:environment] || Rails.env)
|
22
|
+
|
23
|
+
if options[:Host] == 'localhost' &&
|
24
|
+
Rails::LocalSubdomain.enabled_in?(env)
|
25
|
+
message(options[:Port])
|
26
|
+
options[:Host] = '0.0.0.0'
|
27
|
+
end
|
28
|
+
orig_run(app, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.message(port)
|
32
|
+
::Logger.new(STDOUT).info(
|
33
|
+
"Binding 'localhost' to '0.0.0.0' for "\
|
34
|
+
"http://lvh.me:#{port}/ support")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
orig_default
|
38
|
+
end
|
39
|
+
# rubocop: enable Metrics/MethodLength
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rails/local_subdomain/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'rails-local_subdomain'
|
9
|
+
spec.version = Rails::LocalSubdomain::VERSION
|
10
|
+
spec.authors = ['Manuel van Rijn', 'Kyle Whittington']
|
11
|
+
spec.email = ['kyle.thomas.whittington@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'subdomain support in your development environment'
|
14
|
+
spec.description = 'A Rails-specific solution to enable subdomain requests '\
|
15
|
+
'in a local development or test environment.'
|
16
|
+
spec.homepage = 'https://github.com/kWhittington/rails-local_subdomain'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-local_subdomain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manuel van Rijn
|
8
|
+
- Kyle Whittington
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.9'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rubocop
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: A Rails-specific solution to enable subdomain requests in a local development
|
57
|
+
or test environment.
|
58
|
+
email:
|
59
|
+
- kyle.thomas.whittington@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- .rubocop.yml
|
66
|
+
- .ruby-gemset
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/rails/local_subdomain.rb
|
72
|
+
- lib/rails/local_subdomain/rack/handler.rb
|
73
|
+
- lib/rails/local_subdomain/version.rb
|
74
|
+
- rails-local_subdomain.gemspec
|
75
|
+
homepage: https://github.com/kWhittington/rails-local_subdomain
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.14.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: subdomain support in your development environment
|
99
|
+
test_files: []
|