Sha256: 7385e4e7bff84dc21acd575f9f7230d713ef059b5ff7efa997eb92e6bbea7674

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

#!/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{(.*)}, -> (match, env) do
      request_path = env["REQUEST_PATH"]

      return match[1] if opts[:Prefix].length > request_path.length

      local_path = File.join(opts[:Dir], request_path[opts[:Prefix].length..-1])

      if File.directory?(local_path) and
          File.exists?(File.join(local_path, "index.html"))
        File.join(request_path, "index.html")
      else
        match[1]
      end
    end
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobim-0.4.4 bin/jobim