Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of resolved paths. #242

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/falcon/command/paths.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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