webshop/src/app.py

55 lines
1.5 KiB
Python
Raw Normal View History

2020-11-27 03:52:17 +01:00
#!/usr/bin/env python3
import logging
from flask import Flask
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from healthcheck import HealthCheck
2020-11-27 04:18:09 +01:00
from flask_cors import CORS
2020-11-27 03:52:17 +01:00
2020-11-27 23:57:21 +01:00
from utils import Config
2020-11-27 21:13:00 +01:00
from utils import health_database_status, security, user_datastore
2020-11-27 05:49:29 +01:00
from views import ItemView, ProfileView, UploadView, IndexView
2020-11-27 03:52:17 +01:00
2020-11-27 21:13:00 +01:00
from models import db
2020-11-27 03:52:17 +01:00
"""
Main Flask entrypoint
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, UnstableVortex Team"
__module_name__ = "app"
__version__text__ = "1"
2020-11-27 23:57:21 +01:00
# The Flask application is not loaded yet, so we are accessing directly to the configuration values
if Config.SENTRY_DSN:
2020-11-27 03:52:17 +01:00
sentry_sdk.init(
2020-11-27 23:57:21 +01:00
dsn=Config.SENTRY_DSN,
2020-11-27 03:52:17 +01:00
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
2020-11-27 23:57:21 +01:00
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE,
2020-11-27 03:52:17 +01:00
_experiments={"auto_enabling_integrations": True}
)
app = Flask(__name__)
2020-11-27 23:57:21 +01:00
app.config.from_object(Config)
2020-11-27 03:52:17 +01:00
health = HealthCheck()
db.init_app(app)
security.init_app(app, user_datastore)
2020-11-27 23:57:21 +01:00
CORS(app)
2020-11-27 03:52:17 +01:00
2020-11-27 05:49:29 +01:00
for view in [ItemView, ProfileView, UploadView, IndexView]:
2020-11-27 04:10:54 +01:00
view.register(app, trailing_slash=False)
2020-11-27 03:52:17 +01:00
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
@app.before_first_request
def init_db():
db.create_all()