Isolate socketIO, add ping.css to check if can see css AT ALL
Browse files- app.py +48 -45
- static/ping.css +1 -0
- templates/Home.html +1 -0
app.py
CHANGED
|
@@ -20,10 +20,12 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
| 20 |
app = flask.Flask(__name__, static_folder=os.path.join(BASE_DIR, "static"), static_url_path="/static", template_folder=os.path.join(BASE_DIR, "templates"))
|
| 21 |
app.config["DEBUG"] = True
|
| 22 |
app.config["SECRET_KEY"] = "dev-key"
|
|
|
|
|
|
|
| 23 |
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
socketio = SocketIO(app, async_mode="eventlet", cors_allowed_origins="*")
|
| 27 |
|
| 28 |
|
| 29 |
# --- job registry for cancel flags ---
|
|
@@ -31,6 +33,17 @@ socketio = SocketIO(app, async_mode="eventlet", cors_allowed_origins="*")
|
|
| 31 |
CANCEL_FLAGS = {} # {job_id: bool}
|
| 32 |
JOBS = {} # {job_id: {"accs": [...], "started": False}}
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Home
|
| 35 |
@app.route("/")
|
| 36 |
def home():
|
|
@@ -182,49 +195,39 @@ def run_job(job_id, accessions):
|
|
| 182 |
CANCEL_FLAGS.pop(job_id, None)
|
| 183 |
JOBS.pop(job_id, None) # <— tidy queued job
|
| 184 |
|
| 185 |
-
# ---- Socket.IO events ----
|
| 186 |
-
@socketio.on("connect")
|
| 187 |
-
def on_connect():
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
@socketio.on("join")
|
| 191 |
-
def on_join(data):
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
@socketio.on("leave")
|
| 207 |
-
def on_leave(data):
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
@socketio.on("cancel")
|
| 213 |
-
def on_cancel(data):
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
# Show every requests sent to the server
|
| 220 |
-
@app.before_request
|
| 221 |
-
def _dbg_req(): print("REQ:", flask.request.path)
|
| 222 |
-
|
| 223 |
-
# Remove after confirming everything is loading
|
| 224 |
-
@app.after_request
|
| 225 |
-
def add_no_cache_headers(resp):
|
| 226 |
-
resp.headers["Cache-Control"] = "no-store"
|
| 227 |
-
return resp
|
| 228 |
|
| 229 |
@app.route("/about")
|
| 230 |
def about():
|
|
|
|
| 20 |
app = flask.Flask(__name__, static_folder=os.path.join(BASE_DIR, "static"), static_url_path="/static", template_folder=os.path.join(BASE_DIR, "templates"))
|
| 21 |
app.config["DEBUG"] = True
|
| 22 |
app.config["SECRET_KEY"] = "dev-key"
|
| 23 |
+
|
| 24 |
+
# important behind HF proxy
|
| 25 |
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
| 26 |
|
| 27 |
+
# # Socket.IO (logs on for debugging)
|
| 28 |
+
# socketio = SocketIO(app, async_mode="eventlet", cors_allowed_origins="*")
|
| 29 |
|
| 30 |
|
| 31 |
# --- job registry for cancel flags ---
|
|
|
|
| 33 |
CANCEL_FLAGS = {} # {job_id: bool}
|
| 34 |
JOBS = {} # {job_id: {"accs": [...], "started": False}}
|
| 35 |
|
| 36 |
+
# (optional) no-cache while debugging
|
| 37 |
+
@app.after_request
|
| 38 |
+
def nocache(resp):
|
| 39 |
+
resp.headers["Cache-Control"] = "no-store"
|
| 40 |
+
return resp
|
| 41 |
+
|
| 42 |
+
# request log to verify what the proxy is asking for
|
| 43 |
+
@app.before_request
|
| 44 |
+
def _log():
|
| 45 |
+
print("REQ:", request.method, request.path)
|
| 46 |
+
|
| 47 |
# Home
|
| 48 |
@app.route("/")
|
| 49 |
def home():
|
|
|
|
| 195 |
CANCEL_FLAGS.pop(job_id, None)
|
| 196 |
JOBS.pop(job_id, None) # <— tidy queued job
|
| 197 |
|
| 198 |
+
# # ---- Socket.IO events ----
|
| 199 |
+
# @socketio.on("connect")
|
| 200 |
+
# def on_connect():
|
| 201 |
+
# emit("connected", {"ok": True})
|
| 202 |
+
|
| 203 |
+
# @socketio.on("join")
|
| 204 |
+
# def on_join(data):
|
| 205 |
+
# job_id = data.get("job_id")
|
| 206 |
+
# if job_id:
|
| 207 |
+
# join_room(job_id)
|
| 208 |
+
# emit("joined", {"room": job_id})
|
| 209 |
+
|
| 210 |
+
# # Start the job once the client is in the room
|
| 211 |
+
# job = JOBS.get(job_id)
|
| 212 |
+
# if job and not job["started"]:
|
| 213 |
+
# job["started"] = True
|
| 214 |
+
# total = len(job["accs"])
|
| 215 |
+
# # Send an initial queued/total status so the UI can set progress denominator
|
| 216 |
+
# socketio.emit("status", {"state": "queued", "total": total}, room=job_id)
|
| 217 |
+
# socketio.start_background_task(run_job, job_id, job["accs"])
|
| 218 |
+
|
| 219 |
+
# @socketio.on("leave")
|
| 220 |
+
# def on_leave(data):
|
| 221 |
+
# job_id = data.get("job_id")
|
| 222 |
+
# if job_id:
|
| 223 |
+
# leave_room(job_id)
|
| 224 |
+
|
| 225 |
+
# @socketio.on("cancel")
|
| 226 |
+
# def on_cancel(data):
|
| 227 |
+
# job_id = data.get("job_id")
|
| 228 |
+
# if job_id in CANCEL_FLAGS:
|
| 229 |
+
# CANCEL_FLAGS[job_id] = True # flip the flag
|
| 230 |
+
# emit("status", {"state": "cancelling"}, room=job_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
@app.route("/about")
|
| 233 |
def about():
|
static/ping.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
* { outline: 3px solid red; }
|
templates/Home.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
<meta name="description" content="">
|
| 7 |
<!-- meta name="generator" content="Nicepage 7.12.8, nicepage.com"-->
|
| 8 |
<title>Home</title>
|
|
|
|
| 9 |
<link rel="stylesheet" href="{{ url_for('static', filename='nicepage.css') }}">
|
| 10 |
<link rel="stylesheet" href="{{ url_for('static', filename='Home.css') }}">
|
| 11 |
<link id="u-page-google-font" rel="stylesheet" href="https://fonts.googleapis.com/css2?display=swap&family=Roboto:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Lobster:wght@400&family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900">
|
|
|
|
| 6 |
<meta name="description" content="">
|
| 7 |
<!-- meta name="generator" content="Nicepage 7.12.8, nicepage.com"-->
|
| 8 |
<title>Home</title>
|
| 9 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='ping.css') }}" /> <!-- remove afterwards along with static/ping.css-->
|
| 10 |
<link rel="stylesheet" href="{{ url_for('static', filename='nicepage.css') }}">
|
| 11 |
<link rel="stylesheet" href="{{ url_for('static', filename='Home.css') }}">
|
| 12 |
<link id="u-page-google-font" rel="stylesheet" href="https://fonts.googleapis.com/css2?display=swap&family=Roboto:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Lobster:wght@400&family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900">
|