lib/piedesaint.rb in piedesaint-0.1.0 vs lib/piedesaint.rb in piedesaint-0.1.1
- old
+ new
@@ -9,10 +9,11 @@
require 'rack/cache'
require 'rubygems/package'
require "stringio"
require 'time'
+require "uri"
module Piedesaint
module Rack
@@ -41,11 +42,11 @@
@apps = []
@options = options.dup
@options[:folders].each do |root|
root = File.expand_path root
puts "Service root: #{root}"
- @apps << Rack::DirectoryCompress.new(root, app ? app : Rack::FileEtag.new(root) )
+ @apps << ( @options[:tar] ? Rack::DirectoryCompress.new(root, app ? app : Rack::FileEtag.new(root)) : ::Rack::Directory.new(root) )
end
end
def call(env)
response = nil
@@ -74,21 +75,35 @@
::Rack::Builder.app do
use ::Rack::CommonLogger
use ::Rack::ShowExceptions
use ::Rack::SslEnforcer, http_port: options[:http_port], https_port: options[:https_port]
use ::Rack::Deflater
- use ::Rack::Auth::Basic, "Icecreamland" do |username, password|
- ( options[:username] == username ) && ( options[:password] == password )
+
+ if options[:username].nil? or options[:username].empty?
+ puts "Service without Basic Authentication"
+ else
+ use ::Rack::Auth::Basic, "Icecreamland" do |username, password|
+ ( options[:username] == username ) && ( options[:password] == password )
+ end
end
+
use ::Rack::Deflater
- use ::Rack::Cache, verbose: true,
- metastore: 'file:/tmp/rack/meta',
- entitystore: 'file:/tmp/rack/body',
- default_ttl: options[:freshness]
+
+ if options[:metastore].nil? or options[:metastore].empty?
+ puts "Service without cache"
+ else
+ use ::Rack::Cache, verbose: true,
+ metastore: options[:metastore],
+ entitystore: options[:entitystore],
+ default_ttl: options[:freshness]
+ puts "Service cache at #{options[:metastore]} / #{options[:entitystore]}"
+ end
+
map "/" do
run Rack::DirectoriesTraversal.new(options)
end
+ puts "Serving tar'ed folders" if options[:tar]
end
end
def self.execute ( options = {} )
event = ::Puma::Events.new STDOUT, STDERR
@@ -131,9 +146,10 @@
rescue Exception
p "*** Sorry signal SIGTERM not implemented, gracefully stopping feature disabled!"
end
begin
+ puts "Service starting at #{options[:http_port]} -> #{options[:https_port]}"
puma.run.join
rescue Interrupt
graceful_stop puma
end