-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
60 lines (45 loc) · 1.69 KB
/
app.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
from flask import Flask
from flask import current_app
from flask_compress import Compress
from werkzeug.middleware.proxy_fix import ProxyFix
import config
from lib.api import set_database_connection #, collect_sentry_tags
from lib.modules.v4 import make_routes as make_routes_v4
def before_send(event, hint):
a = current_app
if a and a.config.get('TESTING', False):
return None
return event
def make_app():
# import sentry_sdk
# from sentry_sdk.integrations.flask import FlaskIntegration
# sentry_sdk.init(
# dsn="https://[email protected]/3",
# integrations=[FlaskIntegration()],
# before_send=before_send
# )
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=2, x_host=2, x_port=2, x_prefix=2, x_proto=2)
app.config.update(
DEBUG=config.DEBUG_MODE,
PROPAGATE_EXCEPTIONS=True
)
for version in config.API_DB_CONFIG:
make_routes_v4.register(app, 'v4/{}'.format(version))
# Install a hooks to setup the database connection
# according to the API version requested and log request/response.
app.before_request(set_database_connection)
#app.before_request(collect_sentry_tags)
# app.before_request(log_request_info)
# app.after_request(log_response)
# Install HTTP compression hooks
Compress(app)
print(app.url_map)
return app
if __name__ == "__main__":
app = make_app()
try:
ENV_HTTP_LISTEN_PORT = os.environ.get("ENV_HTTP_LISTEN_PORT")
except:
ENV_HTTP_LISTEN_PORT = config.LISTEN_ON_PORT
app.run(host=config.LISTEN_ON_IP, port=ENV_HTTP_LISTEN_PORT, debug=config.DEBUG_MODE, threaded=True)