hosty 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config.ru +13 -0
- data/exe/hosty +9 -0
- data/hosty.gemspec +37 -0
- data/lib/hosty.rb +7 -0
- data/lib/hosty/hosts.rb +31 -0
- data/lib/hosty/scheme_detectable.rb +13 -0
- data/lib/hosty/virtual_hostable.rb +7 -0
- data/lib/portable_string.rb +25 -0
- metadata +123 -0
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
data/Gemfile
ADDED
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
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
data/config.ru
ADDED
data/exe/hosty
ADDED
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
data/lib/hosty/hosts.rb
ADDED
@@ -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,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:
|