lib/grape/app.rb in grape-app-0.4.3 vs lib/grape/app.rb in grape-app-0.5.0
- old
+ new
@@ -7,12 +7,10 @@
require 'active_support/core_ext/time/zones'
require 'rack/cors'
require 'rack/ssl-enforcer'
class Grape::App < Grape::API
- include ActiveSupport::Configurable
-
class << self
# Run initializers
def init!(root = nil)
@root = Pathname.new(root) if root
@@ -34,10 +32,24 @@
# Load app
require_one 'app', 'models'
require_one 'app', 'api'
end
+ # @return [Grape::App::Configuration] the configuration
+ def config
+ @_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config)
+ superclass.config.inheritable_copy
+ else
+ Class.new(Grape::App::Configuration).new
+ end
+ end
+
+ # Configure the app
+ def configure
+ yield config
+ end
+
# @return [Pathname] root path
def root
@root ||= Bundler.root.dup
end
@@ -53,17 +65,13 @@
end
def middleware
config = self.config
@middleware ||= Rack::Builder.new do
+ use Rack::Cors, &config.cors if config.cors
use Rack::SslEnforcer if config.force_ssl
- use Rack::Cors do
- allow do
- origins *Array.wrap(config.cors_allow_origins)
- resource '*', headers: :any, methods: [:get, :post, :options, :delete, :put]
- end
- end if config.cors_allow_origins
+ instance_eval(&config.middleware) if config.middleware
run Grape::App
end
end
@@ -80,6 +88,7 @@
end
end
end
+require 'grape/app/configuration'
require 'grape/app/helpers'