diff --git a/ckan/ckan_app.py b/ckan/ckan_app.py index 57c389caea3..8dc55f2e30b 100644 --- a/ckan/ckan_app.py +++ b/ckan/ckan_app.py @@ -32,7 +32,7 @@ def create_app(): ############################################################################## # Set up routes ############################################################################## - app.add_url_rule('/action/', view_func=ApiView.as_view('api')) + app.add_url_rule('/api/3/action/', view_func=ApiView.as_view('api')) return app diff --git a/ckan/config/middleware.py b/ckan/config/middleware.py index 755dc6779ea..a80afc00dae 100644 --- a/ckan/config/middleware.py +++ b/ckan/config/middleware.py @@ -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"""