Skip to content

Commit

Permalink
Temporary hack to serve JS files from BBB
Browse files Browse the repository at this point in the history
  • Loading branch information
marblestation committed Sep 3, 2019
1 parent 562130e commit 3d8f434
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions adscore/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ def before_request():
if 'auth' not in session or is_expired(session['auth']):
session['auth'] = api.bootstrap()

if ENVIRONMENT != "localhost":
# Temporary hack until:
# - All BBB Javascript is served from one directory and not the root
# - RequireJS requests the files from the right place and not /abs/
import requests
from flask import Response
@app.route('/<filename>.js', methods=['GET',])
@app.route('/abs/<filename>.js', methods=['GET',])
def proxy(filename):
params_dict = {}
if 'v' in request.args:
params_dict['v'] = request.args.get('v')
params = urllib.parse.urlencode(params_dict)
resp = requests.get(f'https://dev.adsabs.harvard.edu/{filename}.js?{params}')
else:
resp = requests.get(f'https://dev.adsabs.harvard.edu/{filename}.js')
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers]
response = Response(resp.content, resp.status_code, headers)
return response

@app.route(SERVER_BASE_URL, methods=['GET'])
def index():
"""
Expand Down

0 comments on commit 3d8f434

Please sign in to comment.