mirror of
https://github.com/kdabir/has.git
synced 2024-11-10 21:26:50 +01:00
36 lines
999 B
Ruby
36 lines
999 B
Ruby
# encoding: UTF-8
|
|
|
|
require './build'
|
|
require 'mongo'
|
|
require 'guillotine'
|
|
|
|
HEADERS_FOR_SHELL = {'Content-Type' => 'text/plain'}
|
|
|
|
## accepts only one parameter `check` with path patterns accepted by build
|
|
map '/dq' do
|
|
run Proc.new { |env|
|
|
commands_to_check = Rack::Request.new(env).params[:check.to_s] || "core/*"
|
|
puts "processing: [#{commands_to_check}]"
|
|
[200, HEADERS_FOR_SHELL, [build(commands_to_check)]]
|
|
}
|
|
end
|
|
|
|
class Shorty < Guillotine::App
|
|
adapter = begin
|
|
mongo_uri = ENV['MONGOLAB_URI'] || 'mongodb://localhost:27017/dq'
|
|
db_name = mongo_uri[%r{/([^/\?]+)(\?|$)}, 1]
|
|
collection = Mongo::MongoClient.from_uri(mongo_uri).db(db_name).collection("shorty")
|
|
Guillotine::MongoAdapter.new(collection)
|
|
rescue
|
|
Guillotine::MemoryAdapter.new
|
|
end
|
|
|
|
set :service => Guillotine::Service.new(adapter, :strip_query => false,
|
|
:required_host => ENV['DOMAIN_RESTRICTION'])
|
|
end
|
|
|
|
map '/check' do
|
|
run Shorty
|
|
end
|
|
|