-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (47 loc) · 1.6 KB
/
main.py
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
import os
from flask import Flask, g
import ApiControllers
from DbClient.db import close_db, init_db, get_db
from QueueInterface.exchange import create_exchanges
from QueueInterface.logs import create_logs_queues
from Utils.consts import configure_private_consts
from werkzeug.contrib.cache import SimpleCache
app = Flask(__name__)
# Set private consts
private_consts = configure_private_consts()
app.private_consts = private_consts
cache = SimpleCache()
print("CACHE: Using Local SimpleCache")
app.cache = cache
# Instantiate socketio interface
sio_class = ApiControllers.Sockio(private_consts, cache)
sio = sio_class.config_socketio(app)
# Instantiate database
# init_db(get_db(private_consts))
# Instantiate db_interfaces
# Create message queue exchanges
create_exchanges(private_consts)
# Create message queues for logs
create_logs_queues(private_consts)
# Instantiate all the APIs with the db_interface passed in the second
ApiControllers.decorate_web_app(app)
ApiControllers.decorate_user_routes(app)
ApiControllers.decorate_bot_routes(app)
ApiControllers.decorate_admin_routes(app)
ApiControllers.decorate_auth_handlers(app)
# Instantiate the error handlers
ApiControllers.decorate_error_handlers(app)
ApiControllers.decorate_auth_error_handlers(app)
# Configure app context teardown
@app.teardown_appcontext
def request_teardown(e):
# Close request db connection
db = g.pop("db", None)
if db is not None:
close_db(db)
# Close request fenix connection
if "fenix" in g:
g.pop("fenix")
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
sio.run(app, port=port)