hoof 0.0.3 → 0.0.4
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.
- data/README.rdoc +5 -1
- data/VERSION +1 -1
- data/hoof.gemspec +1 -1
- data/lib/hoof.rb +10 -1
- data/lib/hoof/cli.rb +16 -0
- data/lib/hoof/http_server.rb +11 -19
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -24,6 +24,10 @@ Then change your /etc/nsswitch.conf like this:
|
|
24
24
|
|
25
25
|
<tt>hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 hoof</tt>
|
26
26
|
|
27
|
+
Then set port redirecting up:
|
28
|
+
|
29
|
+
<tt>hoof route</tt>
|
30
|
+
|
27
31
|
=== Application
|
28
32
|
|
29
33
|
Next step - initialize hoof for application:
|
@@ -40,7 +44,7 @@ Hoof has basic cli for controlling.
|
|
40
44
|
|
41
45
|
Use <tt>hoof</tt> executable to start daemon. Read <tt>hoof help</tt>
|
42
46
|
|
43
|
-
Start your browser and go to http://app.dev
|
47
|
+
Start your browser and go to http://app.dev
|
44
48
|
|
45
49
|
|
46
50
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/hoof.gemspec
CHANGED
data/lib/hoof.rb
CHANGED
@@ -27,7 +27,8 @@ module Hoof
|
|
27
27
|
trap("TERM") { stop }
|
28
28
|
trap("INT") { stop }
|
29
29
|
|
30
|
-
EventMachine::start_server "127.0.0.1",
|
30
|
+
EventMachine::start_server "127.0.0.1", http_port, Hoof::HttpServer
|
31
|
+
EventMachine::start_server "127.0.0.1", https_port, Hoof::HttpServer
|
31
32
|
EventMachine::start_server sock, Hoof::ControlServer
|
32
33
|
end
|
33
34
|
end
|
@@ -41,4 +42,12 @@ module Hoof
|
|
41
42
|
'/tmp/hoof.sock'
|
42
43
|
end
|
43
44
|
|
45
|
+
def self.http_port
|
46
|
+
26080
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.https_port
|
50
|
+
26443
|
51
|
+
end
|
52
|
+
|
44
53
|
end
|
data/lib/hoof/cli.rb
CHANGED
@@ -41,6 +41,22 @@ module Hoof
|
|
41
41
|
control 'status'
|
42
42
|
end
|
43
43
|
|
44
|
+
desc "route", "Redirects http ports to hoof default ports with iptables"
|
45
|
+
def route
|
46
|
+
exec <<-E
|
47
|
+
sudo iptables -t nat -I OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports #{Hoof.http_port} &&
|
48
|
+
sudo iptables -t nat -I OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to-ports #{Hoof.https_port}
|
49
|
+
E
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "unroute", "Destroys hoof iptables redirecting rules"
|
53
|
+
def unroute
|
54
|
+
exec <<-E
|
55
|
+
sudo iptables -t nat -D OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports #{Hoof.http_port} &&
|
56
|
+
sudo iptables -t nat -D OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to-ports #{Hoof.https_port}
|
57
|
+
E
|
58
|
+
end
|
59
|
+
|
44
60
|
private
|
45
61
|
|
46
62
|
def daemon *argv
|
data/lib/hoof/http_server.rb
CHANGED
@@ -9,28 +9,20 @@ module Hoof
|
|
9
9
|
close_connection and return unless host =~ /.dev$/
|
10
10
|
|
11
11
|
name = host.gsub(/.dev$/, '')
|
12
|
-
path = parser.path.split('?', 2)[0]
|
13
|
-
|
14
12
|
application = Hoof.find name
|
15
13
|
|
16
14
|
if application
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
send_data result
|
29
|
-
close_connection_after_writing
|
30
|
-
})
|
31
|
-
rescue
|
32
|
-
puts "Failed to serve #{name}"
|
33
|
-
end
|
15
|
+
begin
|
16
|
+
application.start
|
17
|
+
puts "Serve #{host}#{parser.path}"
|
18
|
+
EventMachine.defer(proc {
|
19
|
+
application.serve data
|
20
|
+
}, proc { |result|
|
21
|
+
send_data result
|
22
|
+
close_connection_after_writing
|
23
|
+
})
|
24
|
+
rescue
|
25
|
+
puts "Failed to serve #{name}"
|
34
26
|
end
|
35
27
|
else
|
36
28
|
close_connection
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pyromaniac
|