Last active
August 29, 2015 14:09
-
-
Save mrbrdo/f0d2b7f1fa62ea934599 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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