local-subdomain 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 637b348da01a0eb3479c53f691fb09b3f784d34d
4
+ data.tar.gz: d323c0cc013e1e78b15392ca9fdce0fde6da1749
5
+ SHA512:
6
+ metadata.gz: 190e2b4d886db70c1828db6cc7ae4ebe88bd32ed28d620b1d5057840ae2f9680aa4d8a0c14b31637a5bb5e239bef72e91be4fa89c0e72120caa885e7eaf55da4
7
+ data.tar.gz: 35c1ad006d4fc3c59619395ada5e2387f3093000042c2d7c7abeba1572ad94fe99e3a3fac9caac98ea22b6041f46035f6314a014585b3397363d2ed4336e7e37
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dev-subdomain.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Manuel van Rijn
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.
@@ -0,0 +1,57 @@
1
+ # local-subdomain: Subdomain support for localhost
2
+
3
+ ## Description
4
+
5
+ This gem helps out when your application depends on subdomain support and you don't want to modify you `/etc/hosts` file all the time for your `development` environment.
6
+
7
+ ## Installation
8
+
9
+ 1. Add the gem to your `Gemfile`
10
+
11
+ ```
12
+ gem 'local-subdomain'
13
+ ```
14
+
15
+ 2. Run `bundle install`
16
+ 3. Include the `LocalSubdomain` module into your `application_controller.rb` (or the controllers that requires subdomain support)
17
+
18
+ ```ruby
19
+ class ApplicationController < ActionController::Base
20
+ include LocalSubdomain
21
+ ....
22
+ end
23
+ ```
24
+
25
+ **NOTE:** Do not force the gem only to be included in the `development` group. Because of the inclusion of the module `LocalSubdomain`, you'll need to have the gem available in every environment.
26
+ The gem itself contains guards to only perform changes when the environment is `development`, so no worries or check it out yourself:
27
+
28
+ - [rack/handler.rb](/lib/local-subdomain/rack/handler.rb#L18)
29
+ - [filters/local_subdomain.rb](/lib/local-subdomain/filters/local_subdomain.rb#L9)
30
+
31
+ ## What it does
32
+
33
+ Basically it does two things:
34
+
35
+ 1. Extends the `Rack::Handler` to make sure we bind to `0.0.0.0` instead of `localhost`
36
+ 2. Adds the `LocalSubdomain` module which executes a `before_filter` to redirect to `http://lvh.me:<port>`
37
+
38
+ ### Rack::Handler
39
+
40
+ This gem uses the domain [http://lvh.me](http://lvh.me) to handle our requests for our subdomain(s). Request to the domain redirects all to `127.0.0.1`.
41
+ This give's us the ability to browse to [http://subsub.lvh.me:3000](http://subsublvh.me:3000) and be handle `request.subdomain` from our controllers.
42
+
43
+ Because we're going to use the external domain [http://lvh.me](http://lvh.me) which redirects to `127.0.0.1` we have to make our server not to bind to `localhost` only.
44
+
45
+ ### LocalSubdomain module
46
+
47
+ This module includes a `before_filter` which will check if the request is served by [http://lvh.me](http://lvh.me). If not it will redirect to the domain.
48
+
49
+ So when we browse to [http://localhost:3000](http://localhost:3000) it will redirect you to [http://lvh.me:3000](http://lvh.me:3000)
50
+
51
+ ## Supported ruby servers
52
+
53
+ I've tested the gem with:
54
+
55
+ * [WEBrick](https://rubygems.org/gems/webrick)
56
+ * [Puma](http://puma.io/)
57
+ * [Thin](http://code.macournoyer.com/thin/)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require 'local-subdomain/version'
2
+ require 'local-subdomain/filters/local_subdomain'
3
+ require 'local-subdomain/rack/handler'
4
+
5
+ module LocalSubdomain
6
+ end
@@ -0,0 +1,18 @@
1
+ module LocalSubdomain
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :redirect_to_lvh_me
6
+ end
7
+
8
+ def redirect_to_lvh_me
9
+ return unless Rails.env.development?
10
+ served_by_lvh_me = !request.env['SERVER_NAME'][/lvh.me$/].nil?
11
+ return if served_by_lvh_me
12
+
13
+ http = request.env['rack.url_scheme']
14
+ port = request.env['SERVER_PORT']
15
+ path = request.env['ORIGINAL_FULLPATH']
16
+ redirect_to "#{http}://lvh.me:#{port}#{path}"
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # Override the Rack::Handler to bind to 0.0.0.0 which is required to support
2
+ # http://lvh.me redirects
3
+
4
+ module Rack
5
+ module Handler
6
+ class << self
7
+ alias_method :orig_default, :default
8
+ end
9
+
10
+ def self.default(options = {})
11
+ orig_default.instance_eval do
12
+ class << self
13
+ alias_method :orig_run, :run
14
+ end
15
+
16
+ def self.run(app, options = {})
17
+ env = (options[:environment] || Rails.env)
18
+ if options[:Host] == 'localhost' && env == 'development'
19
+ message(options[:Port])
20
+ options.merge!(Host: '0.0.0.0')
21
+ end
22
+ orig_run(app, options)
23
+ end
24
+
25
+ def self.message(port)
26
+ puts '****************************************************************************************'
27
+ puts "* Override binding 'localhost' to '0.0.0.0' for http://lvh.me:#{port}/ support"
28
+ puts '****************************************************************************************'
29
+ end
30
+ end
31
+ orig_default
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module LocalSubdomain
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'local-subdomain/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'local-subdomain'
8
+ spec.version = LocalSubdomain::VERSION
9
+ spec.authors = ['Manuel van Rijn']
10
+ spec.email = ['manuel@manuelvanrijn.nl']
11
+
12
+ spec.summary = 'subdomain support in your development environment'
13
+ spec.description = "This gem helps out when your application depends on subdomain support and you don't want to modify you /etc/hosts file all the time for your development environment."
14
+ spec.homepage = 'https://github.com/manuelvanrijn/local-subdomain'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.9'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: local-subdomain
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Manuel van Rijn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This gem helps out when your application depends on subdomain support
42
+ and you don't want to modify you /etc/hosts file all the time for your development
43
+ environment.
44
+ email:
45
+ - manuel@manuelvanrijn.nl
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/local-subdomain.rb
56
+ - lib/local-subdomain/filters/local_subdomain.rb
57
+ - lib/local-subdomain/rack/handler.rb
58
+ - lib/local-subdomain/version.rb
59
+ - local-subdomain.gemspec
60
+ homepage: https://github.com/manuelvanrijn/local-subdomain
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: subdomain support in your development environment
84
+ test_files: []