()
| 10 | |
| 11 | |
| 12 | def create_app(): |
| 13 | app = Flask(__name__) |
| 14 | |
| 15 | # Initialize database connection |
| 16 | try: |
| 17 | DatabaseSession.initialize() |
| 18 | logger.info("Database connection initialized successfully") |
| 19 | |
| 20 | except Exception as e: |
| 21 | logger.error(f"Failed to initialize database connection: {str(e)}") |
| 22 | raise |
| 23 | |
| 24 | # Add CORS support |
| 25 | |
| 26 | @app.after_request |
| 27 | def after_request(response): |
| 28 | # Allow all origins in development environment |
| 29 | response.headers.add("Access-Control-Allow-Origin", "*") |
| 30 | response.headers.add( |
| 31 | "Access-Control-Allow-Headers", "Content-Type,Authorization" |
| 32 | ) |
| 33 | response.headers.add( |
| 34 | "Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS" |
| 35 | ) |
| 36 | return response |
| 37 | |
| 38 | # Create file server handler |
| 39 | file_handler = FileServerHandler( |
| 40 | os.path.join(os.getenv("APP_ROOT", "/app"), "resources", "raw_content") |
| 41 | ) |
| 42 | |
| 43 | @app.route("/raw_content/", defaults={"path": ""}) |
| 44 | @app.route("/raw_content/<path:path>") |
| 45 | def serve_content(path=""): |
| 46 | return file_handler.handle_request(path, request.path) |
| 47 | |
| 48 | # Register all routes |
| 49 | init_routes(app) |
| 50 | |
| 51 | # Clean up database connection only when the application shuts down |
| 52 | @app.teardown_appcontext |
| 53 | def cleanup_db(exception): |
| 54 | pass |
| 55 | |
| 56 | return app |
| 57 | |
| 58 | |
| 59 | app = create_app() |
no test coverage detected