From 124cb54b74c277df1af335aa894dc70f018a96e3 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Thu, 15 Oct 2020 09:53:50 -0400 Subject: [PATCH] WSGI doesn't support socketio --- Dockerfile | 4 +++- src/app.py | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7d1bb1..a7a20c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,7 @@ WORKDIR /root/ RUN pip install -r requirements.txt +WORKDIR /root/src -CMD [ "gunicorn", "-b", "0.0.0.0:25565", "src.app:app" ] \ No newline at end of file +CMD [ "python", "app.py" ] +# CMD [ "gunicorn", "-b", "0.0.0.0:25565","--workers", "3", "--timeout", "86400", "src.app:app" ] \ No newline at end of file diff --git a/src/app.py b/src/app.py index bc39afb..8486651 100644 --- a/src/app.py +++ b/src/app.py @@ -1,16 +1,18 @@ from flask import * from random import randint as rint -from src.config import Config -from src.host import HostForm -from src.join import JoinForm -from src.sec import gencode, dohash, whitelist +from config import Config +from host import HostForm +from join import JoinForm +from sec import gencode, dohash, whitelist from logging.config import dictConfig from flask_socketio import SocketIO, emit, join_room, leave_room import json +from dotenv import load_dotenv +load_dotenv() # Loading logging preferences -with open("src/logger.json", "r") as f: +with open("logger.json", "r") as f: dconf = json.load(f) # Establishing logger @@ -44,7 +46,7 @@ def host(): hash = dohash(hostcode) resp = redirect(url_for("play", hash=hash)) resp.set_cookie("_gid", str(hostcode)) - with open("src/templates/games.json", "r") as f: + with open("templates/games.json", "r") as f: tmp = json.load(f) games[hash] = tmp games[hash]["hostcode"] = hostcode @@ -57,7 +59,7 @@ def host(): session.permanent = True return resp - with open("src/templates/games.json", "r") as f: + with open("templates/games.json", "r") as f: tmp = json.load(f) default = [tmp["tossup"], tmp["bonus"], tmp["power"], tmp["negs"]] return render_template('host.html', title="Host Game", version=str(version), form=form, default=default) @@ -136,7 +138,10 @@ def on_join(data): if dohash(gid) == room: username = "host" join_room(str(room)) - msg = {"locked": games[room]["locked"], "players": games[room]["players"]} + try: + msg = {"locked": games[room]["locked"], "players": games[room]["players"]} + except KeyError: + return render_template('gamenotfound.html', title="Join Game", version=str(version)) emit('player_join_event', msg, room=room)