Class: Falcon::Configuration
- Inherits:
-
Object
- Object
- Falcon::Configuration
- Defined in:
- lib/falcon/configuration.rb
Instance Attribute Summary collapse
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Method Summary collapse
- #add(name, *parents, &block) ⇒ Object
- #each ⇒ Object
- #host(name, *parents, &block) ⇒ Object
-
#initialize(verbose = false) ⇒ Configuration
constructor
A new instance of Configuration.
- #load_file(path) ⇒ Object
- #proxy(name, *parents, &block) ⇒ Object
- #rack(name, *parents, &block) ⇒ Object
Constructor Details
#initialize(verbose = false) ⇒ Configuration
Returns a new instance of Configuration.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 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 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/falcon/configuration.rb', line 68 def initialize(verbose = false) @environments = {} @verbose = verbose add(:ssl) do ssl_session_id {"falcon"} end add(:host, :ssl) do ssl_certificate_path {File.("ssl/certificate.pem", root)} ssl_certificate {OpenSSL::X509::Certificate.new(File.read(ssl_certificate_path))} ssl_private_key_path {File.("ssl/private.key", root)} ssl_private_key {OpenSSL::PKey::RSA.new(File.read(ssl_private_key_path))} ssl_context do OpenSSL::SSL::SSLContext.new.tap do |context| context.cert = ssl_certificate context.key = ssl_private_key context.session_id_context = ssl_session_id context.set_params context.setup end end end add(:lets_encrypt, :ssl) do lets_encrypt_root '/etc/letsencrypt/live' ssl_certificate_path {File.join(lets_encrypt_root, , "fullchain.pem")} ssl_private_key_path {File.join(lets_encrypt_root, , "privkey.pem")} end add(:self_signed, :ssl) do ssl_context do contexts = Localhost::Authority.fetch() contexts.server_context.tap do |context| context.alpn_select_cb = lambda do |protocols| if protocols.include? "h2" return "h2" elsif protocols.include? "http/1.1" return "http/1.1" elsif protocols.include? "http/1.0" return "http/1.0" else return nil end end context.session_id_context = "falcon" end end end add(:proxy, :host) do endpoint {::Async::HTTP::Endpoint.parse(url)} end add(:rack, :host) do config_path {::File.("config.ru", root)} middleware do ::Falcon::Server.middleware( ::Rack::Builder.parse_file(config_path).first, verbose: verbose ) end 'localhost' scheme 'https' protocol {::Async::HTTP::Protocol::HTTP2} ipc_path {::File.("server.ipc", root)} endpoint {ProxyEndpoint.unix(ipc_path, protocol: protocol, scheme: scheme, authority: )} bound_endpoint do Async::Reactor.run do Async::IO::SharedEndpoint.bound(endpoint) end.wait end server do ::Falcon::Server.new(middleware, bound_endpoint, protocol, scheme) end end end |
Instance Attribute Details
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
157 158 159 |
# File 'lib/falcon/configuration.rb', line 157 def environments @environments end |
Instance Method Details
#add(name, *parents, &block) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/falcon/configuration.rb', line 159 def add(name, *parents, &block) raise KeyError.new("#{name} is already set", key: name) if @environments.key?(name) environments = parents.map{|name| @environments.fetch(name)} parent = Build::Environment.combine(*environments) @environments[name] = Build::Environment.new(parent, name: name, &block) end |
#each ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/falcon/configuration.rb', line 169 def each return to_enum unless block_given? @environments.each do |name, environment| if environment.include?(:authority) yield environment end end end |
#host(name, *parents, &block) ⇒ Object
179 180 181 182 183 |
# File 'lib/falcon/configuration.rb', line 179 def host(name, *parents, &block) add(name, :host, *parents, &block).tap do |environment| environment[:authority] = name end end |
#load_file(path) ⇒ Object
197 198 199 |
# File 'lib/falcon/configuration.rb', line 197 def load_file(path) self.instance_eval(File.read(path), File.realpath(path)) end |
#proxy(name, *parents, &block) ⇒ Object
185 186 187 188 189 |
# File 'lib/falcon/configuration.rb', line 185 def proxy(name, *parents, &block) add(name, :proxy, *parents, &block).tap do |environment| environment[:authority] = name end end |
#rack(name, *parents, &block) ⇒ Object
191 192 193 194 195 |
# File 'lib/falcon/configuration.rb', line 191 def rack(name, *parents, &block) add(name, :rack, *parents, &block).tap do |environment| environment[:authority] = name end end |