Spaces:
Paused
Paused
Create flask-app/app.py
Browse files- flask-app/app.py +25 -0
flask-app/app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, jsonify
|
| 2 |
+
from werkzeug.middleware.dispatcher import DispatcherMiddleware
|
| 3 |
+
from werkzeug.serving import run_simple
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
app.secret_key = "change-this-secret-key" # CHANGE THIS - it is public via the bridge
|
| 7 |
+
app.config["APPLICATION_ROOT"] = "/app" # matches the public path below
|
| 8 |
+
|
| 9 |
+
# ----- Your routes, templates, sessions, login logic stay EXACTLY as they are -----
|
| 10 |
+
|
| 11 |
+
@app.route("/")
|
| 12 |
+
def index():
|
| 13 |
+
return render_template("index.html")
|
| 14 |
+
|
| 15 |
+
@app.route("/status")
|
| 16 |
+
def status():
|
| 17 |
+
return jsonify({"status": "running", "app": "flask-app"})
|
| 18 |
+
|
| 19 |
+
# ------------------------------------------------------------------------------
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
# Serve the whole app under the /app prefix so url_for() matches the public path,
|
| 23 |
+
# and bind to 0.0.0.0 so the root proxy can reach it.
|
| 24 |
+
wrapped = DispatcherMiddleware(Flask("empty"), {"/app": app})
|
| 25 |
+
run_simple("0.0.0.0", 9001, wrapped)
|