move config around

This commit is contained in:
Konstantin Haase 2012-09-11 13:50:02 +02:00
parent bff18a278c
commit f05f841a46
4 changed files with 22 additions and 12 deletions

View File

@ -6,7 +6,7 @@ GIT
GIT
remote: git://github.com/rkh/gh.git
revision: 907f35326579495a54c7ee2b030b6292d2e5d9ef
revision: 5aa120dd493f1430fc1af9d97363daea5c4c3415
specs:
gh (0.8.0)
addressable
@ -32,7 +32,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: c3459dc0610cf91632c9aa4e873ed45f4fe1b713
revision: b71c3be388451581f2ca60e6fd862c2bfc56bfb6
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.3)

View File

@ -36,25 +36,26 @@ class Travis::Api::App
#
# This method is not threadsafe, but called when loading
# the environment, so no biggy.
def self.setup
return if setup?
setup_travis
load_endpoints
setup_endpoints
@setup = true
def self.setup(options = {})
setup! unless setup?
Endpoint.set(options)
end
def self.new(options = {})
setup(options) if options
super()
end
attr_accessor :app
def initialize(options = {})
def initialize
@app = Rack::Builder.app do
use Rack::Protection::PathTraversal
use Rack::SSL if Endpoint.production?
use ActiveRecord::ConnectionAdapters::ConnectionManagement
Middleware.subclasses.each { |m| use(m) }
endpoints = Endpoint.subclasses
endpoints -= [Endpoint::Home] if options[:disable_root_endpoint]
endpoints.each { |e| map(e.prefix) { run(e.new) } }
Endpoint.subclasses.each { |e| map(e.prefix) { run(e.new) } }
end
end
@ -65,6 +66,13 @@ class Travis::Api::App
private
def self.setup!
setup_travis
load_endpoints
setup_endpoints
@setup = true
end
def self.setup_travis
Travis::Database.connect
end

View File

@ -4,6 +4,7 @@ class Travis::Api::App
# Superclass for HTTP endpoints. Takes care of prefixing.
class Endpoint < Responder
set(:prefix) { "/" << name[/[^:]+$/].underscore }
set disable_root_endpoint: false
register :scoping
before { content_type :json }

View File

@ -7,6 +7,7 @@ class Travis::Api::App
# Landing point. Redirects web browsers to [API documentation](#/docs/).
get '/' do
pass if settings.disable_root_endpoint?
redirect to('/docs/') if request.preferred_type('application/json', 'text/html') == 'text/html'
{ 'hello' => 'world' }
end