Skip to content

Commit

Permalink
Better handling of resolved paths. (#242)
Browse files Browse the repository at this point in the history
* Fixes #241.
  • Loading branch information
ioquatix committed May 10, 2024
1 parent 0e66cff commit 77346bb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/falcon/command/paths.rb
Expand Up @@ -12,16 +12,18 @@ module Paths
# Resolve a set of `@paths` that may contain wildcards, into a sorted, unique array.
# @returns [Array(String)]
def resolved_paths(&block)
@paths.collect do |path|
Dir.glob(path)
end.flatten.sort.uniq.each(&block)
if @paths
@paths.collect do |path|
Dir.glob(path)
end.flatten.sort.uniq.each(&block)
end
end

# Build a configuration based on the resolved paths.
def configuration
configuration = Configuration.new

self.resolved_paths.each do |path|
self.resolved_paths do |path|
path = File.expand_path(path)

configuration.load_file(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/command/proxy.rb
Expand Up @@ -56,7 +56,7 @@ def call
buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
buffer.puts "- To reload: kill -HUP #{Process.pid}"

self.resolved_paths.each do |path|
self.resolved_paths do |path|
buffer.puts "- Loading configuration from #{path}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/command/redirect.rb
Expand Up @@ -55,7 +55,7 @@ def call
buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
buffer.puts "- To reload: kill -HUP #{Process.pid}"

self.resolved_paths.each do |path|
self.resolved_paths do |path|
buffer.puts "- Loading configuration from #{path}"
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/falcon/command/virtual.rb
Expand Up @@ -3,6 +3,8 @@
# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.

require 'async/service'

require_relative '../environment/virtual'

require 'samovar'
Expand Down
10 changes: 7 additions & 3 deletions lib/falcon/environment/configured.rb
Expand Up @@ -16,9 +16,13 @@ def configuration_paths

# All the falcon application configuration paths, with wildcards expanded.
def resolved_configuration_paths
configuration_paths.flat_map do |path|
Dir.glob(path)
end.uniq
if configuration_paths = self.configuration_paths
configuration_paths.flat_map do |path|
Dir.glob(path)
end.uniq
else
[]
end
end

def configuration
Expand Down
15 changes: 15 additions & 0 deletions test/falcon/command/virtual.rb
Expand Up @@ -42,6 +42,21 @@ def around

let(:insecure_client) {Async::HTTP::Client.new(command.insecure_endpoint, retries: 0)}

with 'no paths' do
let (:paths) {[]}

it "should still start correctly" do
request = Protocol::HTTP::Request.new("https", "hello.localhost", "GET", "/index")

Async do
response = insecure_client.get("/index")

expect(response).to be(:failure?)
pp response
end
end
end

it "gets redirected from insecure to secure endpoint" do
request = Protocol::HTTP::Request.new("http", "hello.localhost", "GET", "/index")

Expand Down

0 comments on commit 77346bb

Please sign in to comment.