hosty 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00869051be7d97f98e4ebc2f562743e6b4ee0c7c
4
+ data.tar.gz: 61aec49f9845a4e8c3189ae0c1b833df288061bf
5
+ SHA512:
6
+ metadata.gz: c6431644278be6510c1f1328f43d6d7b0ff914a79c2ffd50b7db1fab414906249c9a06c2dd6bd7188f82eea8be19352b4888a1a4fcf195053c48131c560d7fef
7
+ data.tar.gz: cb8d1db939a94aead86289586b4bb55402850c53d78e7c5adfa9adb15f5c1898b73f39e688ade8393b8f481920a6d783dd675aa314c2d19d56728789507258c5
data/.gitignore ADDED
@@ -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 hosty.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Shintaro Kojima
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,46 @@
1
+ # Hosty
2
+
3
+ ## Overview
4
+
5
+ /etc/hosts based tiny reverse proxy.
6
+
7
+ You may sometimes run a web application on ```http://localhost:3000``` during development, or
8
+ sometimes you may configure a local port forward on ```http://localhost:8080``` with SSH to access web server behind firewalls.
9
+
10
+ Hosty loads your ```/etc/hosts``` and acts as reverse proxies to simplify the URLs.
11
+ It allows you to manage mappings of local server name and port on ```/etc/hosts```.
12
+
13
+ ## Installation
14
+
15
+ ```zsh
16
+ $ gem install hosty
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Run:
22
+
23
+ ```zsh
24
+ sudo hosty
25
+ ```
26
+
27
+ If you have lines below in your ```/etc/hosts```:
28
+
29
+ ```
30
+ 127.0.0.1 internal.example.com internal # :8080
31
+ 127.0.0.1 rails # :3000
32
+ ```
33
+
34
+ Hosty accepts ```http(s)://internal.example.com/foo``` locally and proxies it
35
+ into ```http(s)://internal.example.com:8080/foo``` for example. URL scheme will be kept intact.
36
+
37
+ Shortly,
38
+
39
+ * http(s)://internal.example.com → http(s)://internal.example.com:8080
40
+ * http(s)://internal → http(s)://internal:8080
41
+ * http(s)://rails → http(s)://rails:3000
42
+
43
+
44
+ ## Copyright and License
45
+
46
+ Copyright (c) 2016 Shintaro Kojima. Code released under the [MIT license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/test*.rb']
9
+ t.verbose = true
10
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hosty"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config.ru ADDED
@@ -0,0 +1,13 @@
1
+ require 'hosty'
2
+
3
+ use Rack::ReverseProxy do
4
+ Hosty::Hosts.mapping do |map|
5
+ port = map[:port]
6
+
7
+ map[:servers].each do |server|
8
+ reverse_proxy /(.*)/, "//#{server}:#{port}/$1", vhost: server
9
+ end
10
+ end
11
+ end
12
+
13
+ run proc {}
data/exe/hosty ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack'
4
+
5
+ config = File.expand_path('../../config.ru', __FILE__)
6
+
7
+ Thread.start { Rack::Server.start(config: config, Port: 80) }
8
+ Thread.start { Rack::Server.start(config: config, Port: 443) }.join # single ^C to kill all
9
+
data/hosty.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hosty"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Shintaro Kojima"]
9
+ spec.email = ["goodies@codeout.net"]
10
+
11
+ spec.summary = "/etc/hosts based tiny reverse proxy."
12
+
13
+ spec.description = <<-EOS
14
+ /etc/hosts based tiny reverse proxy.
15
+
16
+ You may sometimes run a web application on http://localhost:3000 during development, or
17
+ sometimes you may configure local port forward on http://localhost:8080 with SSH to access web servers behind firewalls.
18
+
19
+ Hosty loads your /etc/hosts and acts as a reverse proxy to simplify the URLs.
20
+ It allows you to manage mappings of local server name and port on /etc/hosts.
21
+ EOS
22
+
23
+ spec.homepage = "https://github.com/codeout/hosty"
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "rack-reverse-proxy"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "test-unit", "~> 3.0"
35
+
36
+ spec.required_ruby_version = '>= 2.1.0'
37
+ end
data/lib/hosty.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'hosty/hosts'
2
+ require 'hosty/scheme_detectable'
3
+ require 'hosty/virtual_hostable'
4
+ require 'rack/reverse_proxy'
5
+
6
+ RackReverseProxy::RoundTrip.prepend Hosty::VirtualHostable
7
+ RackReverseProxy::Rule::Candidate.prepend Hosty::SchemeDetectable
@@ -0,0 +1,31 @@
1
+ require 'portable_string'
2
+
3
+ module Hosty
4
+ class Hosts
5
+ using PortableString
6
+
7
+ class << self
8
+ def mapping(&block)
9
+ parse File.read('/etc/hosts'), &block
10
+ end
11
+
12
+
13
+ private
14
+
15
+ def parse(str, &block)
16
+ content(str).each_line do |l|
17
+ columns = l.split
18
+ next unless columns[0].local_address?
19
+
20
+ if columns.last.port_number?
21
+ yield servers: columns[1..-2], port: columns.last.port_number
22
+ end
23
+ end
24
+ end
25
+
26
+ def content(raw)
27
+ raw.skip_comment_lines.shorten_port_definitions
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module Hosty
2
+ module SchemeDetectable
3
+ def url
4
+ original = super
5
+
6
+ if original[0..1] == '//'
7
+ "#{env['rack.url_scheme']}:#{original}"
8
+ else
9
+ original
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Hosty
2
+ module VirtualHostable
3
+ def rules
4
+ super.select {|r| r.options[:vhost] == env['SERVER_NAME'] }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module PortableString
2
+ refine String do
3
+ def local_address?
4
+ self == '127.0.0.1' || self == '::1'
5
+ end
6
+
7
+ def skip_comment_lines
8
+ gsub(/^ *#.*\n/, '')
9
+ end
10
+
11
+ def shorten_port_definitions
12
+ gsub(/# *(:\d+).*/) { $1 }
13
+ end
14
+
15
+ def port_number?
16
+ port_number != nil
17
+ end
18
+
19
+ def port_number
20
+ if self =~ /^:(\d+)$/
21
+ $1.to_i
22
+ end
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hosty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shintaro Kojima
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-reverse-proxy
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
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: |
70
+ /etc/hosts based tiny reverse proxy.
71
+
72
+ You may sometimes run a web application on http://localhost:3000 during development, or
73
+ sometimes you may configure local port forward on http://localhost:8080 with SSH to access web servers behind firewalls.
74
+
75
+ Hosty loads your /etc/hosts and acts as a reverse proxy to simplify the URLs.
76
+ It allows you to manage mappings of local server name and port on /etc/hosts.
77
+ email:
78
+ - goodies@codeout.net
79
+ executables:
80
+ - hosty
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - Gemfile
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - bin/console
90
+ - bin/setup
91
+ - config.ru
92
+ - exe/hosty
93
+ - hosty.gemspec
94
+ - lib/hosty.rb
95
+ - lib/hosty/hosts.rb
96
+ - lib/hosty/scheme_detectable.rb
97
+ - lib/hosty/virtual_hostable.rb
98
+ - lib/portable_string.rb
99
+ homepage: https://github.com/codeout/hosty
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: "/etc/hosts based tiny reverse proxy."
122
+ test_files: []
123
+ has_rdoc: