Skip to content

Instantly share code, notes, and snippets.

@mrbrdo
Last active August 29, 2015 14:09
Show Gist options
  • Save mrbrdo/f0d2b7f1fa62ea934599 to your computer and use it in GitHub Desktop.
Save mrbrdo/f0d2b7f1fa62ea934599 to your computer and use it in GitHub Desktop.
# /config/application.rb
config.middleware.insert_before ActionDispatch::ParamsParser, "SelectiveStack"
# /config/initializers/omniauth.rb
::OmniAuthConfig = Proc.new do
provider :github, # ...
end
# /app/middleware
class SelectiveStack
def initialize(app)
@app = app
end
def call(env)
if env["PATH_INFO"].start_with?("/api/")
@app.call(env)
else
middleware_stack.build(@app).call(env)
end
end
private
def middleware_stack
@middleware_stack ||= begin
ActionDispatch::MiddlewareStack.new.tap do |middleware|
# needed for OmniAuth
middleware.use ActionDispatch::Cookies
middleware.use Rails.application.config.session_store, Rails.application.config.session_options
middleware.use OmniAuth::Builder, &OmniAuthConfig
# needed for Doorkeeper /oauth views
middleware.use ActionDispatch::Flash
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment