Skip to content

Commit

Permalink
Changed dispatch middleware to check against known Flask paths
Browse files Browse the repository at this point in the history
Unfortunately we need to check the path for the request against a known
list of partial paths that Flask knows about - and then we route those
requests to Flask.
  • Loading branch information
rossjones committed Sep 4, 2015
1 parent c89326e commit 358646a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ckan/ckan_app.py
Expand Up @@ -32,7 +32,7 @@ def create_app():
##############################################################################
# Set up routes
##############################################################################
app.add_url_rule('/action/<func_name>', view_func=ApiView.as_view('api'))
app.add_url_rule('/api/3/action/<func_name>', view_func=ApiView.as_view('api'))

return app

Expand Down
30 changes: 25 additions & 5 deletions ckan/config/middleware.py
Expand Up @@ -180,15 +180,35 @@ def make_app(conf, full_stack=True, static_files=True, **app_conf):
from werkzeug.wsgi import DispatcherMiddleware
from ckan_app import create_app

app = DispatcherMiddleware(app, {
'/api/4': create_app()
})
#from ckan_app import create_app
#app = PathDispatcher(app, create_app)

app = FlaskDispatcher(app, create_app)
return app


class FlaskDispatcher(object):
"""
Dispatches requests either to the CKAN Pylons app, or
if the request path starts with one known by Flask, the
Flask app.
"""

FLASK_PATHS = (
"/api/3",
)

def __init__(self, default_app, create_app):
self.default_app = default_app
self.create_app = create_app

def __call__(self, environ, start_response):
path = environ["PATH_INFO"]
if path.startswith(FlaskDispatcher.FLASK_PATHS):
return self.create_app()(environ, start_response)

return self.default_app(environ, start_response)



class I18nMiddleware(object):
"""I18n Middleware selects the language based on the url
eg /fr/home is French"""
Expand Down

0 comments on commit 358646a

Please sign in to comment.