from pathlib import Path from flask import Flask, request app = Flask(__name__) LIVE = Path("livez") LIVE.write_text("ok") @app.route("/") def hello_world(): version = "v3" if "5000" in request.base_url: mode = "local" header_color = "#a0dfa0" elif "30001" in request.base_url: mode = "active" header_color = "#a0c0df" elif "30002" in request.base_url: mode = "preview" header_color = "#dfa0df" else: mode = "unknown" header_color = "#dfc0a0" import time LIVE.write_text("no") time.sleep(10) LIVE.write_text("ok") return f""" {mode}: Hello, World!

{mode}: Hello, World! {version}

Hello, World!

Mode: {mode}

Version: {version}

""" @app.route("/healthz") def healthz(): # return "failed", 500 return "I'm still here.", 200 @app.route("/livez") def livez(): if LIVE.read_text() == "ok": return "All done working here." return "I'm working here!", 500