init flask-socketio + put app in a custom class
This commit is contained in:
parent
a536e9c82b
commit
03ab987f78
@ -2,27 +2,34 @@ import flask
|
||||
import os
|
||||
|
||||
from truthseeker.routes import routes_api, routes_ui
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
class TruthSeekerApp(flask.Flask):
|
||||
|
||||
app = flask.Flask("truthseeker")
|
||||
def __init__(self):
|
||||
super().__init__("truthseeker")
|
||||
self.set_app_secret()
|
||||
self.socketio_app = SocketIO(self)
|
||||
|
||||
def set_secret(app):
|
||||
if os.path.isfile("instance/secret.txt"):
|
||||
f = open("instance/secret.txt", "r")
|
||||
app.config["SECRET_KEY"] = f.read()
|
||||
f.close()
|
||||
print("Read secret from secret.txt !")
|
||||
else:
|
||||
import secrets
|
||||
app.config["SECRET_KEY"] = secrets.token_hex()
|
||||
os.makedirs("instance", exist_ok=True)
|
||||
f = open("instance/secret.txt", "w")
|
||||
f.write(app.config["SECRET_KEY"])
|
||||
f.close()
|
||||
print("Generated secret and wrote to secret.txt !")
|
||||
def run_app(self):
|
||||
self.socketio_app.run(self)
|
||||
|
||||
set_secret(app)
|
||||
def set_app_secret(self):
|
||||
if os.path.isfile("instance/secret.txt"):
|
||||
f = open("instance/secret.txt", "r")
|
||||
self.config["SECRET_KEY"] = f.read()
|
||||
f.close()
|
||||
print("Read secret from secret.txt !")
|
||||
else:
|
||||
import secrets
|
||||
self.config["SECRET_KEY"] = secrets.token_hex()
|
||||
os.makedirs("instance", exist_ok=True)
|
||||
f = open("instance/secret.txt", "w")
|
||||
f.write(self.config["SECRET_KEY"])
|
||||
f.close()
|
||||
print("Generated secret and wrote to secret.txt !")
|
||||
|
||||
app = TruthSeekerApp()
|
||||
|
||||
app.register_blueprint(routes_api.routes_api, url_prefix="/api/v1")
|
||||
app.register_blueprint(routes_ui.routes_ui, url_prefix="/")
|
||||
|
Loading…
Reference in New Issue
Block a user