Skip to content

Commit 7bcb2a4

Browse files
authored
Merge pull request #20 from obilodeau/deps-update-260503
Dependency updates
2 parents 11e7218 + 3b9cba7 commit 7bcb2a4

10 files changed

Lines changed: 703 additions & 786 deletions

File tree

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ install-dev:
3030

3131
# ── Run dev servers (Flask + Vite) in one terminal ──────────────────────────
3232

33-
run:
34-
@python ceopardy.py & backend=$$!; \
35-
npm run dev --prefix frontend & frontend=$$!; \
36-
trap "kill $$backend $$frontend 2>/dev/null" INT TERM; \
37-
wait $$backend $$frontend
33+
# Reinstalls when package.json is newer than the install marker.
34+
frontend/node_modules/.package-lock.json: frontend/package.json
35+
npm install --prefix frontend
36+
@touch frontend/node_modules/.package-lock.json
37+
38+
run: frontend/node_modules/.package-lock.json
39+
@exec sh -c 'trap "kill 0" INT TERM; \
40+
python run.py & \
41+
npm run dev --prefix frontend & \
42+
wait'

README.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You need Python, pip, virtualenv and Node.js (LTS). The tl;dr:
4141
source .venv/bin/activate.fish # fish
4242
npm install --prefix frontend
4343
npm run build --prefix frontend
44-
python ceopardy.py
44+
python run.py
4545

4646
`make venv` creates `.venv/` and installs both runtime and dev requirements.
4747

@@ -63,12 +63,12 @@ Then open http://127.0.0.1:5000/host[the host view] to set up the game.
6363
http://127.0.0.1:5000/[The players' view] (also known as the viewer) can be
6464
opened at any time.
6565

66-
`python ceopardy.py` runs the built-in dev server (debug + reloader). For
66+
`python run.py` runs the built-in dev server (debug + reloader). For
6767
production, run it under gunicorn with the eventlet worker. Socket.IO requires
6868
a single worker process unless you also configure a Redis message queue:
6969

7070
pip install gunicorn
71-
gunicorn -k eventlet -w 1 -b 127.0.0.1:5000 'ceopardy:app'
71+
gunicorn -k eventlet -w 1 -b 127.0.0.1:5000 'run:app'
7272

7373
Put nginx (or similar) in front for TLS and to expose it on the network — the
7474
app itself binds to localhost because the host interface has no auth.
@@ -80,7 +80,7 @@ Run Flask and Vite side by side. Vite hot-reloads the UI and proxies
8080
`/api` and `/socket.io` to Flask.
8181

8282
# terminal 1 - Flask
83-
python ceopardy.py
83+
python run.py
8484

8585
# terminal 2 - Vite dev server
8686
npm run dev --prefix frontend

api/routes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ def init_game():
230230
{"id": "message1", "html": content},
231231
namespace=GAME_NS,
232232
)
233-
# Old viewers that are still on a legacy URL should just bounce.
234-
app.socketio.emit("redirect", {"url": "/"}, namespace=GAME_NS)
235233

236234
return jsonify(result="success")
237235

ceopardy.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* broadcast realtime state changes on the /game Socket.IO namespace
2626
* serve the built SPA (and some legacy static assets)
2727
28-
For development run Flask (`python ceopardy.py`) and Vite (`npm run dev`)
28+
For development run Flask (`python run.py`) and Vite (`npm run dev`)
2929
side by side. Vite proxies /api and /socket.io to Flask.
3030
"""
3131

@@ -146,6 +146,7 @@ def create_app():
146146

147147
from controller import Controller
148148

149+
db.create_all()
149150
app.controller = Controller()
150151

151152
# Register the REST blueprint. It depends on app.controller being set.
@@ -160,10 +161,3 @@ def teardown_controller(exception): # noqa: ARG001
160161
_ctl = None
161162

162163
return app
163-
164-
165-
if __name__ == "__main__":
166-
create_app()
167-
# WARNING: This app is not ready to be exposed on the network.
168-
# Game host interface would be exposed.
169-
socketio.run(app, host="127.0.0.1", port=5000, debug=True)

controller.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,22 @@ def db_backup_and_create_new():
471471
"""
472472
# TODO we might need to lock this thing to avoid state issues with viewers
473473
previous_roundfile = Game.query.one().round_filename
474-
_bkp = "ceopardy_{}_{}.db".format(
474+
_bkp_name = "ceopardy_{}_{}.db".format(
475475
datetime.now().strftime("%Y-%m-%d_%H%M"), previous_roundfile
476476
)
477-
app.logger.info("Backing up current game to {}".format(_bkp))
477+
# SQLite URI is resolved against app.instance_path; the live file lives there too.
478+
db_path = os.path.join(app.instance_path, config["DATABASE_FILENAME"])
479+
bkp_path = os.path.join(app.instance_path, _bkp_name)
480+
app.logger.info("Backing up current game to {}".format(bkp_path))
481+
db.session.remove()
478482
db.engine.dispose()
479-
os.rename(config["BASE_DIR"] + config["DATABASE_FILENAME"], config["BASE_DIR"] + _bkp)
480-
db.session = db.create_scoped_session()
483+
if os.path.exists(db_path):
484+
os.rename(db_path, bkp_path)
485+
else:
486+
app.logger.warning("Expected DB file at %s was missing; skipping rename", db_path)
481487
db.create_all()
482488
Controller._init()
483-
app.logger.info("SQL Engine reconnected, empty database recreated." + "We are ready to go!")
489+
app.logger.info("SQL Engine reconnected, empty database recreated. We are ready to go!")
484490

485491

486492
class GameProblem(Exception):

0 commit comments

Comments
 (0)