-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (66 loc) · 2.55 KB
/
Copy pathapp.py
File metadata and controls
78 lines (66 loc) · 2.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# app.py
# Application entry point for DevPath.
#
# Responsibilities:
# - Create the Flask app instance
# - Register the main Blueprint from routes/
# - Register the global error boundary via errors/handlers.py
# - Start the development server when run directly
#
# Business logic, recommendation scoring, and data loading all live in
# the utils/ and routes/ packages, not here.
from flask import Flask
from routes.main_routes import main
from config import Config
from errors.handlers import register_error_handlers
app = Flask(__name__)
# Load config settings into Flask's internal config manager properly
app.config.from_object(Config)
# Register all routes defined in the main Blueprint (This handles your '/' route!)
app.register_blueprint(main)
# Register the global error boundary (handles 400, 403, 404, 405, 429, 500,
# and any unhandled Exception). Must be called after Blueprint registration
# so Blueprint-level error handlers take precedence where defined.
register_error_handlers(app)
@app.after_request
def add_security_headers(response):
"""Add basic security headers to all responses."""
response.headers["X-Frame-Options"] = "DENY"
response.headers["X-Content-Type-Options"] = "nosniff"
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
response.headers["Permissions-Policy"] = (
"geolocation=(), microphone=(), camera=()"
)
response.headers["Content-Security-Policy"] = (
"default-src 'self'; "
"script-src 'self' 'unsafe-inline'; "
"style-src 'self' 'unsafe-inline'; "
"img-src 'self' data:; "
"font-src 'self'; "
"connect-src 'self'; "
"frame-ancestors 'none'"
)
response.headers["Content-Security-Policy"] = (
"default-src 'self'; "
"script-src 'self' 'unsafe-inline'; "
"style-src 'self' 'unsafe-inline'; "
"img-src 'self' data:; "
"font-src 'self'; "
"connect-src 'self'; "
"frame-ancestors 'none'"
)
return response
# Expose the 500 handler at module level so existing tests can import it
# directly: from app import app, internal_server_error
def internal_server_error(error):
"""Proxy kept for backward compatibility with test_basic.py."""
from errors.handlers import internal_server_error as _handler
return _handler(error)
if __name__ == "__main__":
import os
debug_mode = os.environ.get("FLASK_DEBUG", "False").lower() in ("true", "1")
app.run(
host="0.0.0.0",
port=int(os.environ.get("PORT", 5000)),
debug=debug_mode,
)