Module: Tunnels

Defined in:
lib/tunnels.rb,
lib/tunnels/version.rb

Defined Under Namespace

Classes: HttpClient, HttpProxy, HttpsClient, HttpsProxy

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.helpObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tunnels.rb', line 40

def self.help
  "Usage:\n  multitunnels [from to] [from2 to2] ...\n\nExamples:\n  multitunnels 443 3000\n  multitunnels localhost:443 localhost:3000\n  multitunnels https://:443 http://:3000\n  multitunnels https://localhost:443 http://localhost:3000\n\n  HELP\nend\n"

.run!(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tunnels.rb', line 11

def self.run!(params)
  maps = parse_params params

  maps.each do |from, to|
    puts "#{from[0]}://#{from[1]}:#{from[2]} --(--)--> #{to[0]}://#{to[1]}:#{to[2]}"
  end

  maps = group_params maps

  EventMachine.run do
    servers = {}
    maps.each do |from, map|
      scheme, port = from
      servers[from] ||= case scheme
                        when :https
                          EventMachine.start_server('127.0.0.1', port, HttpsProxy, map)
                        when :http
                          EventMachine.start_server('127.0.0.1', port, HttpProxy, map)
                        end
    end
    puts "Ready :)"
  end
rescue RuntimeError => e
  STDERR.puts e.message
  STDERR.puts "Maybe you should run on `sudo`"
rescue ClientError => e
  STDERR.puts e.message
end