#!/usr/bin/env ruby require 'pathname' file = Pathname.new(__FILE__).realpath $:.unshift File.expand_path("../../lib", file) require 'jobim' opts = Jobim::CLI.run!(*ARGV) exit if opts.nil? require 'rack' require 'rack/rewrite' app = Rack::Builder.new do use Rack::Rewrite do rewrite %r{(.*)/$}, "$1/index.html", :if => -> (env) { File.exists?("#{$1}/index,html") } end use Rack::CommonLogger, STDOUT map opts[:Prefix] do run Rack::Directory.new(opts[:Dir]) end end puts ">>> Serving #{opts[:Dir]}" Rack::Handler::Thin.run(app, opts) do |server| if opts[:Daemonize] server.pid_file = 'jobim.pid' server.log_file = 'jobim.log' server.daemonize end Thin::Logging.silent = opts[:Quiet] end