From c27d9593c279cd591e2bb1efc282733bca5a3fc3 Mon Sep 17 00:00:00 2001 From: Zeb Burke-Conte Date: Thu, 6 Apr 2017 22:18:45 -0700 Subject: [PATCH] Take out server-side proxying infrastructure --- src/base/templates/base.html | 8 +++++ src/base/urls.py | 4 --- src/base/views.py | 64 ++++++------------------------------ 3 files changed, 18 insertions(+), 58 deletions(-) diff --git a/src/base/templates/base.html b/src/base/templates/base.html index 5fede19ba1..cbc03a00c3 100644 --- a/src/base/templates/base.html +++ b/src/base/templates/base.html @@ -281,9 +281,17 @@

} +<<<<<<< fa20320487d039d0e61102467dc883750e35130c +======= + + + {% handlebarsjs '(.*)' precompile register_partials %} {% handlebarsjs 'pages/*' precompile %} diff --git a/src/base/urls.py b/src/base/urls.py index 2cb0e45be5..7d789a3d18 100644 --- a/src/base/urls.py +++ b/src/base/urls.py @@ -16,10 +16,6 @@ # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), - url(r'^api/(.*)$', views.api, name='api_proxy'), - url(r'^users/(.*)$', views.users, name='auth_proxy'), - url(r'^download/(.*).csv$', views.csv_download, name='csv_proxy'), - url(r'^dataset/(?P[^/]+)/(?P.*)$', views.api, name='dataset_api_proxy'), url(r'^place/(?P[^/]+)$', views.index, name='place'), url(r'^', views.index, name='index'), ) diff --git a/src/base/views.py b/src/base/views.py index 858ad384af..c311ccbe3b 100644 --- a/src/base/views.py +++ b/src/base/views.py @@ -22,55 +22,12 @@ log = logging.getLogger(__name__) - -def make_api_root(dataset_root): - components = dataset_root.split('/') - if dataset_root.endswith('/'): - return '/'.join(components[:-4]) + '/' - else: - return '/'.join(components[:-3]) + '/' - -def make_auth_root(dataset_root): - return make_api_root(dataset_root) + 'users/' - -def make_resource_uri(resource, root): - resource = resource.strip('/') - root = root.rstrip('/') - uri = '%s/%s' % (root, resource) - return uri - - -class ShareaboutsApi (object): - def __init__(self, dataset_root): - self.dataset_root = dataset_root - self.auth_root = make_auth_root(dataset_root) - self.root = make_api_root(dataset_root) - - def get(self, resource, default=None, **kwargs): - uri = make_resource_uri(resource, root=self.dataset_root) - res = requests.get(uri, params=kwargs, - headers={'Accept': 'application/json'}) - return (res.text if res.status_code == 200 else default) - - def current_user(self, default=u'null', **kwargs): - uri = make_resource_uri('current', root=self.auth_root) - res = requests.get(uri, headers={'Accept': 'application/json'}, **kwargs) - - return (res.text if res.status_code == 200 else default) - - @ensure_csrf_cookie def index(request, place_id=None): # Load app config settings config = get_shareabouts_config(settings.SHAREABOUTS.get('CONFIG')) config.update(settings.SHAREABOUTS.get('CONTEXT', {})) - # Get initial data for bootstrapping into the page. - dataset_root = settings.SHAREABOUTS.get('DATASET_ROOT') - if (dataset_root.startswith('file:')): - dataset_root = request.build_absolute_uri(reverse('api_proxy', args=('',))) - api = ShareaboutsApi(dataset_root=dataset_root) - # Get the content of the static pages linked in the menu. pages_config = config.get('pages', []) pages_config_json = json.dumps(pages_config) @@ -101,24 +58,20 @@ def index(request, place_id=None): "browser": {"name": "", "version": None}, "platform": {"name": "", "version": None} }) - - place = None - if place_id and place_id != 'new': - place = api.get('places/' + place_id) - if place: - place = json.loads(place) + + # Get initial data for bootstrapping into the page. + dataset_root = settings.SHAREABOUTS.get('DATASET_ROOT') + if (dataset_root.startswith('file:')): + dataset_root = request.build_absolute_uri(reverse('api_proxy', args=('',))) context = {'config': config, - 'user_token_json': user_token_json, 'pages_config': pages_config, 'pages_config_json': pages_config_json, 'user_agent_json': user_agent_json, # Useful for customized meta tags - 'place': place, - - 'API_ROOT': api.root, - 'DATASET_ROOT': api.dataset_root, + 'API_ROOT': dataset_root, + 'DATASET_ROOT': dataset_root } return render(request, 'index.html', context) @@ -362,6 +315,7 @@ def readonly_file_api(request, path, datafilename='data.json'): return readonly_response(request, feature) else: raise Http404 +<<<<<<< fa20320487d039d0e61102467dc883750e35130c def api(request, path, **kwargs): @@ -465,3 +419,5 @@ def csv_download(request, path): response['Content-disposition'] = 'attachment; filename=' + filename return response +======= +>>>>>>> Take out server-side proxying infrastructure