vagrant-reverse-proxy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26d9391f462c1912d503f0fc872ad82f1171bf26
4
- data.tar.gz: 31b74fb24938a8ad11f549bf0750900b1ecef175
3
+ metadata.gz: 37af02ecaff09d53c0bf6b227f8739ef4e9b6f24
4
+ data.tar.gz: 510a0c70893fa0571c93f8646072bbd9d616b040
5
5
  SHA512:
6
- metadata.gz: 10f1d65e39fcfd7877ecdaf91a8d47708179eb9e5cd32e2e73be19ca559e749d475f5edebaa87d6a442e9ccd32b52baec142fbdb7ef100b7ad2c46247a006174
7
- data.tar.gz: ecaec449938977b8555bc5811bac8ac1eba378804119a6809cf75df5775a6d0ff103cdcc9f1c591b2c470ab23d0acf9c83385f02f995113b26cbae6fe8b5aa5f
6
+ metadata.gz: c6293d0ed3a1e1d71d916b940afd676c682b9c58440581e90e918be72ae3a3ef29b5d4f478f3448da9065841152bf91437a24e6ec6dbd5a03aee9e7cb83445eb
7
+ data.tar.gz: 6aa66013e96de2139073c52d6b1552ef3532a0548aa86ed76dc34e858d87d2ed29db2e7af96c1b3a590f25f523edc1053f15e289faf9b02445e1fc6ce2b8894a
data/README.md CHANGED
@@ -60,6 +60,19 @@ set that up, you can override the `vhosts` option:
60
60
  This will proxy `http://localhost/foo.test` and
61
61
  `http://localhost/bar.test` to this VM, with a matching `Host` header.
62
62
 
63
+ If you want to customize the vhost path, you can use a hash instead of
64
+ an array:
65
+
66
+ config.reverse_proxy.vhosts = {
67
+ "foo-test" => "foo.test",
68
+ "bar" => "bar.test"
69
+ "bar-altport" => {:host => "bar.test", :port => 8080}
70
+ }
71
+
72
+ As you can see, this allows you to define which port to connect to
73
+ instead of the default port (which is port 80).
74
+
75
+
63
76
  ## Adding proxy support to your application
64
77
 
65
78
  This plugin will instruct NGINX to pass the following headers to your
@@ -5,8 +5,6 @@ module VagrantPlugins
5
5
  module Action
6
6
  include Vagrant::Action::Builtin
7
7
 
8
- # We (currently) don't distinguish between upping and downing a
9
- # machine; we always write a complete config with all machines.
10
8
  def self.add_machine
11
9
  Vagrant::Action::Builder.new.tap do |builder|
12
10
  builder.use(ConfigValidate)
@@ -59,19 +59,24 @@ module VagrantPlugins
59
59
  if @config.reverse_proxy.vhosts
60
60
  vhosts = @config.reverse_proxy.vhosts
61
61
  else
62
- vhosts = [machine.config.vm.hostname || machine.name]
62
+ host = machine.config.vm.hostname || machine.name
63
+ vhosts = {host => host}
63
64
  end
64
65
  ip = get_ip_address(machine)
65
- vhosts.collect do |vhost| <<EOF
66
- location /#{vhost}/ {
67
- proxy_set_header Host #{vhost};
66
+ vhosts.collect do |path, vhost|
67
+ # Rewrites are matches literally by nginx, which means
68
+ # http://host:80/... will NOT match http://host/...!
69
+ port_suffix = vhost[:port] == 80 ? '' : ":#{vhost[:port]}"
70
+ <<EOF
71
+ location /#{path}/ {
72
+ proxy_set_header Host #{vhost[:host]};
68
73
  proxy_set_header X-Forwarded-For $remote_addr;
69
74
  proxy_set_header X-Forwarded-Host $host;
70
75
  proxy_set_header X-Forwarded-Port $server_port;
71
- proxy_set_header X-Base-Url http://$host:$server_port/#{vhost}/;
76
+ proxy_set_header X-Base-Url http://$host:$server_port/#{path}/;
72
77
 
73
- proxy_pass http://#{ip}/;
74
- proxy_redirect http://#{vhost}/ /#{vhost}/;
78
+ proxy_pass http://#{ip}#{port_suffix}/;
79
+ proxy_redirect http://#{vhost[:host]}#{port_suffix}/ /#{path}/;
75
80
  }
76
81
  EOF
77
82
  end.join("\n")
@@ -12,7 +12,23 @@ module VagrantPlugins
12
12
 
13
13
  def finalize!
14
14
  @enabled = false if @enabled == UNSET_VALUE
15
- @vhosts = nil if @vhosts == UNSET_VALUE
15
+ if @vhosts == UNSET_VALUE
16
+ @vhosts = nil
17
+ elsif @vhosts.is_a?(Array)
18
+ # Convert to canonical hash form of
19
+ # {path => {:host => name, :port => num}}
20
+ vhosts_hash = {}
21
+ @vhosts.each {|entry| vhosts_hash[entry] = {:host => entry, :port => 80} }
22
+ @vhosts = vhosts_hash
23
+ elsif @vhosts.is_a?(Hash)
24
+ @vhosts.each do |key, value|
25
+ if (value.is_a?(String))
26
+ @vhosts[key] = {:host => value, :port => 80}
27
+ else
28
+ value[:port] ||= 80
29
+ end
30
+ end
31
+ end
16
32
  end
17
33
 
18
34
  def validate(machine)
@@ -22,8 +38,27 @@ module VagrantPlugins
22
38
  errors << 'enabled must be a boolean'
23
39
  end
24
40
 
25
- unless @vhosts.instance_of?(Array) || @vhosts == nil || @vhosts == UNSET_VALUE
26
- errors << 'vhosts must be an array of hostnames (or nil to use default name)'
41
+ if @vhosts.instance_of?(Array)
42
+ @vhosts.each do |vhost|
43
+ unless (vhost.is_a?(String) || vhost.is_a?(Hash))
44
+ errors << "vhost #{vhost} is not a string or hash"
45
+ end
46
+ end
47
+ elsif @vhosts.instance_of?(Hash)
48
+ @vhosts.each do |path, vhost|
49
+ unless path.is_a?(String)
50
+ errors << "vhost path `#{path}' is not a string"
51
+ end
52
+ unless vhost.is_a?(String) || vhost.is_a?(Hash)
53
+ errors << "Vhost `#{vhost}' for path `#{path}' is not a string or hash"
54
+ else
55
+ if vhost.is_a?(Hash) && !vhost[:host]
56
+ errors << "Vhost `#{vhost}' for path `#{path}' has no :host key"
57
+ end
58
+ end
59
+ end
60
+ elsif @vhosts != nil && @vhosts != UNSET_VALUE
61
+ errors << 'vhosts must be an array of hostnames, a string=>string hash or nil'
27
62
  end
28
63
 
29
64
  { 'Reverse proxy configuration' => errors.compact }
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ReverseProxy
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-reverse-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler