-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (43 loc) · 1.66 KB
/
Copy pathapp.py
File metadata and controls
59 lines (43 loc) · 1.66 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
"""OnTracker web app — token-paste setup + scheduled email briefs."""
from __future__ import annotations
import logging
import os
import secrets
import sentry_sdk
from flask import Flask
from flask_cors import CORS
from core.jobs import startup
from extensions import limiter
from routes.main import main_bp
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
log = logging.getLogger(__name__)
# Error/performance monitoring. Only initialises when SENTRY_DSN is set, so local
# dev stays quiet and the DSN never lives in source. The Flask integration is
# picked up automatically once flask is importable.
_sentry_dsn = os.environ.get("SENTRY_DSN")
if _sentry_dsn:
sentry_sdk.init(
dsn=_sentry_dsn,
environment=os.environ.get("SENTRY_ENVIRONMENT", "production"),
# Off: this app handles student emails/usernames — don't ship request
# headers/IPs or PII to Sentry.
send_default_pii=False,
# Forward logging.* records to Sentry.
enable_logs=True,
)
log.info("Sentry initialised (env=%s)", os.environ.get("SENTRY_ENVIRONMENT", "production"))
def create_app() -> Flask:
app = Flask(__name__)
app.secret_key = os.environ.get("SECRET_KEY") or secrets.token_hex(32)
CORS(app, resources={r"/*": {"origins": "*"}})
# Initialize extensions
limiter.init_app(app)
# Register blueprints
app.register_blueprint(main_bp)
# Startup logic (DB init, restore schedules, start scheduler)
startup()
return app
app = create_app()
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5001))
app.run(debug=False, host="0.0.0.0", port=port)