Class: H2OConfigurator::Site
- Inherits:
-
Object
- Object
- H2OConfigurator::Site
- Defined in:
- lib/h2o-configurator/builder.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #access_log_file ⇒ Object
- #cert_dir ⇒ Object
- #domains ⇒ Object
- #htpasswd_file ⇒ Object
-
#initialize(dir) ⇒ Site
constructor
A new instance of Site.
- #make_config ⇒ Object
- #make_handlers ⇒ Object
- #make_host_config(port = 80) ⇒ Object
- #make_https_redirect_host_config(port = 80) ⇒ Object
- #private_key_file ⇒ Object
- #server_certificate_file ⇒ Object
Constructor Details
#initialize(dir) ⇒ Site
Returns a new instance of Site.
57 58 59 60 |
# File 'lib/h2o-configurator/builder.rb', line 57 def initialize(dir) @dir = dir @name = dir.basename.to_s end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
54 55 56 |
# File 'lib/h2o-configurator/builder.rb', line 54 def dir @dir end |
#name ⇒ Object
Returns the value of attribute name.
55 56 57 |
# File 'lib/h2o-configurator/builder.rb', line 55 def name @name end |
Instance Method Details
#access_log_file ⇒ Object
163 164 165 |
# File 'lib/h2o-configurator/builder.rb', line 163 def access_log_file H2OConfigurator::H2OLogDir / "#{@name}.access.log" end |
#cert_dir ⇒ Object
147 148 149 |
# File 'lib/h2o-configurator/builder.rb', line 147 def cert_dir H2OConfigurator::CertBaseDir / @name end |
#domains ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/h2o-configurator/builder.rb', line 82 def domains ([''] + DomainPrefixes).map do |prefix| ([''] + DomainSuffixes).map do |suffix| "#{prefix}#{@name}#{suffix}" end end.flatten end |
#htpasswd_file ⇒ Object
159 160 161 |
# File 'lib/h2o-configurator/builder.rb', line 159 def htpasswd_file @dir / '.htpasswd' end |
#make_config ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/h2o-configurator/builder.rb', line 62 def make_config config = {} if cert_dir.exist? https_redirect_host_config = make_https_redirect_host_config(80) host_config = make_host_config(443) else https_redirect_host_config = nil host_config = make_host_config(80) end domains.each do |domain| if https_redirect_host_config config["#{domain}:80"] = https_redirect_host_config config["#{domain}:443"] = host_config else config["#{domain}:80"] = host_config end end config end |
#make_handlers ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/h2o-configurator/builder.rb', line 121 def make_handlers handlers = [] if htpasswd_file.exist? handlers << RubyHandler.make( %Q{ require 'htpasswd' Htpasswd.new('#{htpasswd_file}', '#{@name}') } ) end handlers << RubyHandler.make( %Q{ require '#{H2OConfigurator::InstalledRedirectHandlerFile}' H2OConfigurator::RedirectHandler.new }, ) handlers << RubyHandler.make( %Q{ require '#{H2OConfigurator::InstalledAutoExtensionHandlerFile}' H2OConfigurator::AutoExtensionHandler.new } ) handlers << FileDirHandler.make(@dir) handlers end |
#make_host_config(port = 80) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/h2o-configurator/builder.rb', line 90 def make_host_config(port=80) config = { 'listen' => { 'port' => port, }, 'access-log' => access_log_file.to_s, 'setenv' => { 'HOST_DIR' => @dir.to_s }, 'paths' => { '/' => make_handlers, }, } if server_certificate_file.exist? && private_key_file.exist? config['listen']['ssl'] = { 'certificate-file' => server_certificate_file.to_s, 'key-file' => private_key_file.to_s, } end config end |
#make_https_redirect_host_config(port = 80) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/h2o-configurator/builder.rb', line 110 def make_https_redirect_host_config(port=80) { 'listen' => port, 'paths' => { '/' => { 'redirect' => "https://#{@name}", } } } end |
#private_key_file ⇒ Object
155 156 157 |
# File 'lib/h2o-configurator/builder.rb', line 155 def private_key_file cert_dir / H2OConfigurator::PrivateKeyFilename end |
#server_certificate_file ⇒ Object
151 152 153 |
# File 'lib/h2o-configurator/builder.rb', line 151 def server_certificate_file cert_dir / H2OConfigurator::ServerCertificateFilename end |