72 lines
2.5 KiB
Python
Raw Permalink Normal View History

2025-07-29 12:50:35 -07:00
import logging
2023-02-24 12:39:18 -08:00
import os
2025-07-29 12:50:35 -07:00
import pathlib
2023-02-24 12:39:18 -08:00
import sys
import flask
2025-07-29 12:50:35 -07:00
log = logging.getLogger()
pipe_stderr = logging.StreamHandler(sys.stderr)
pipe_stderr.setLevel(logging.DEBUG)
log.addHandler(pipe_stderr)
if getattr(sys, "frozen", False):
path_appdir = pathlib.Path(sys._MEIPASS)
else:
path_appdir = pathlib.Path.cwd()
log.critical(path_appdir)
desktop_mode = False
app = flask.Flask("seagull-game", root_path=path_appdir)
2023-02-24 12:39:18 -08:00
orig_url_for = app.url_for
xml_namespaces = {
"items": "seagull:rules/items"
}
2023-02-28 14:21:03 -08:00
#REDIS_HOST="stub-implementation.example.net"
#REDIS_PORT=6379
#REDIS_USER="seagull"
#REDIS_PASS="i am not a real password"
#state_cache = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, username=REDIS_USER, password=REDIS_PASS)
2023-02-24 12:39:18 -08:00
def url_for_override(endpoint, *posargs, _anchor=None, _method=None, _scheme=None, _external=None, self=app, **values):
if endpoint == "static":
# bandaid for #1
2025-07-29 12:50:35 -07:00
if not os.path.exists(path_appdir / "static" / values["filename"]):
log.warning("requested {0} from local file, but it doesn't exist in this container. Redirecting to CDN...\n".format(values["filename"]))
2023-02-24 12:39:18 -08:00
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)
2023-02-24 12:39:18 -08:00
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")
2023-02-13 12:57:30 -08:00
base_context_live = True
@app.route("/core/ping")
2025-07-29 12:50:35 -07:00
def healthcheck_ping():
return flask.Response("OK", content_type="text/plain")