import os import sys import flask app = flask.Flask("seagull-game", root_path="/app") orig_url_for = app.url_for def url_for_override(endpoint, *posargs, _anchor=None, _method=None, _scheme=None, _external=None, self=app, **values): if endpoint == "static": # bandaid for #1 if not os.path.exists("/app/static/" + values["filename"]): sys.stderr.write("WARN:: requested {0} from local file, but it doesn't exist in this container. Redirecting to CDN...\n".format(values["filename"])) sys.stderr.flush() return "https://cdn.otl-hga.net/seagull/" + values["filename"] return orig_url_for(endpoint, *posargs, _anchor=_anchor, _method=_method, _scheme=_scheme, _external=_external, **values) app.url_for = url_for_override base_context = {} base_context_live = False def render_base_context(): global base_context global base_context_live base_context["svchost"] = flask.request.host domain_components = flask.request.host.split(".") base_domain = ".".join(domain_components[-2:]) # all this wind up for... if base_domain == "otl-hga.net": # production, use assets from S3 base_context["styles"] = ["https://cdn.otl-hga.net/seagull/css/seagull.css"] base_context["scripts"] = ["https://cdn.otl-hga.net/seagull/js/seagull.js"] base_context["seagull_pic"] = "https://cdn.otl-hga.net/seagull/image/seagull.jpg" else: # dev, serve files from here print(base_domain) base_context["styles"] = [app.url_for("static", filename="css/seagull.css")] base_context["scripts"] = [app.url_for("static", filename="js/seagull.js")] base_context["seagull_pic"] = app.url_for("static", filename="image/seagull.jpg") base_context_live = True @app.route("/core/ping") def aws_healthcheck_ping(): return flask.Response("OK", content_type="text/plain")