-
-
Notifications
You must be signed in to change notification settings - Fork 630
Expand file tree
/
Copy pathserver.py
More file actions
63 lines (44 loc) · 1.79 KB
/
Copy pathserver.py
File metadata and controls
63 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
from flask import Flask
from app import config
from app.db import Session
# the app is served behind nginx which uses http and not https
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
def create_light_app() -> Flask:
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = config.DB_URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
@app.teardown_appcontext
def shutdown_session(response_or_exc):
Session.remove()
return app
def create_app() -> Flask:
if config.MAINTENANCE_MODE:
from maintenance_app import create_maintenance_app
return create_maintenance_app()
else:
from simplelogin_app import create_simplelogin_app
return create_simplelogin_app()
def local_main():
config.COLOR_LOG = True
app = create_app()
if not config.MAINTENANCE_MODE:
# enable flask toolbar
from flask_debugtoolbar import DebugToolbarExtension
# Disabled in python 3.12 as it collides with the default CPython profiler
app.config["DEBUG_TB_PROFILER_ENABLED"] = False
app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False
app.debug = True
DebugToolbarExtension(app)
# disable the sqlalchemy debug panels because of "IndexError: pop from empty list" from:
# duration = time.time() - conn.info['query_start_time'].pop(-1)
# app.config["DEBUG_TB_PANELS"] += ("flask_debugtoolbar_sqlalchemy.SQLAlchemyPanel",)
app.run(debug=True, port=7777)
# uncomment to run https locally
# LOG.d("enable https")
# import ssl
# context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# context.load_cert_chain("local_data/cert.pem", "local_data/key.pem")
# app.run(debug=True, port=7777, ssl_context=context)
if __name__ == "__main__":
local_main()