Skip to content

Commit

Permalink
Fix map js issue (which occurred only at AWS)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Duplyakin committed Feb 14, 2024
1 parent cae36df commit 57bdd28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions proto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, render_template, request, jsonify
from flask import Flask, render_template, request, jsonify, Response
from flask_cors import CORS
from threading import Thread
from time import sleep
Expand Down Expand Up @@ -211,6 +211,7 @@ def timeseries_to_12_by_24(df, styling=True, format="html"):

# Identify the current environment
# This method came from checking tap-api-prod ECS container on 02/13/2023
# URL_prefix should NOT include "/" at the end, otherwise there will be errors
if os.environ.get('AWS_EXECUTION_ENV') == "AWS_ECS_EC2":
running_in_aws = True
if port == 80 or port == "80":
Expand All @@ -219,10 +220,14 @@ def timeseries_to_12_by_24(df, styling=True, format="html"):
URL_prefix = "https://dw-tap.nrel.gov:%s" % str(port)
else:
running_in_aws = False
if port == 80 or port == "80":
URL_prefix = "http://localhost"
else:
URL_prefix = "http://localhost:%s" % str(port)

# This case is for running locally (container should be accessed via port 8080 even though inside it the server runs on part 80)
URL_prefix = "http://localhost:8080"

# if port == 80 or port == "80":
# URL_prefix = "http://localhost"
# else:
# URL_prefix = "http://localhost:%s" % str(port)

# Now that URL_prefix is determined for the current env, prepare templates from universal ones
# Universal here means that those template can be used for AWS and non-AWS envs
Expand Down Expand Up @@ -520,7 +525,10 @@ def get_infomap():
try:
lat = float(req_args["lat"])
lon = float(req_args["lon"])
return get_infomap_script(lat, lon)
#return get_infomap_script(lat, lon)

# The following should solve the issue "Refused to execite script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type"
return Response(get_infomap_script(lat, lon), mimetype='text/javascript')
except Exception as e:
return ""

Expand Down Expand Up @@ -578,6 +586,10 @@ def status():
return output

@app.route('/', methods=['GET'])
def serve_slash():
return render_template("info.html")

#@app.route('/', methods=['GET'])
@app.route('/<path:path>')
def root(path):
""" Main routine that servies multiple endpoints """
Expand Down
2 changes: 1 addition & 1 deletion templates/by_address.html
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
}

document.getElementById("fetching_msg").innerHTML = "";
window.location.href = "http://localhost:8080" + endpoint + "?height=" + hub_height + "m&" + latlon + "&year=" + years;
window.location.href = "http://localhost:8080" + "/" + endpoint + "?height=" + hub_height + "m&" + latlon + "&year=" + years;
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion templates/on_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
else {
endpoint = "ts";
}
window.location.href = "http://localhost:8080" + endpoint + "?height=" + hub_height + "m&lat=" + lat + "&lon=" + lon + "&year=" + years;
window.location.href = "http://localhost:8080" +"/" + endpoint + "?height=" + hub_height + "m&lat=" + lat + "&lon=" + lon + "&year=" + years;
}
</script>

Expand Down

0 comments on commit 57bdd28

Please sign in to comment.