-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.py
More file actions
55 lines (47 loc) · 1.83 KB
/
server.py
File metadata and controls
55 lines (47 loc) · 1.83 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
# [In-project modules]
from utils.logger import initialize_logging_module
initialize_logging_module() # has to break the rule here otherwise the logging module won't work
from config import ServerConfig
from backend.account_related.account_related_blueprint import account_related_blueprint
from backend.independent.independent_blueprint import independent_blueprint
from backend.printer_related.printer_related_blueprint import printer_related_blueprint
from frontend.frontend_blueprint import frontend_blueprint
from frontend.admin.admin_blueprint import admin_blueprint
# [Python native modules]
import logging
# [Third-party modules]
from flask import Flask
import waitress
# don't use __name__ for this one, but for ALL others
main_logger = logging.getLogger('main')
from utils.json_logger import JSONLogger
lgr = JSONLogger('logs/print_data.log')
lgr.write({'use': False})
if __name__ == '__main__':
server = Flask(__name__)
# load all blueprints here
server.register_blueprint(account_related_blueprint)
server.register_blueprint(independent_blueprint)
server.register_blueprint(printer_related_blueprint)
server.register_blueprint(frontend_blueprint)
server.register_blueprint(admin_blueprint)
try:
main_logger.info('All blueprints loaded, server starts up.')
# start server
if ServerConfig.debug:
# use debug server
server.run(
host = ServerConfig.host,
debug = ServerConfig.debug,
port = ServerConfig.port
)
else:
waitress.serve(
server,
host = ServerConfig.host,
threads = ServerConfig.maximum_threads,
port = ServerConfig.port
)
except Exception as e:
main_logger.exception('Server crashed.')
exit()