A Python port of the Invisible Internet Project (I2P)
1"""Flask application factory for the I2P Router Console.
2
3Creates and configures the Flask app with Jinja2 templates,
4route blueprints, and the RouterContext adapter.
5
6Ported from net.i2p.router.web.RouterConsoleRunner.
7"""
8
9from __future__ import annotations
10
11import os
12from flask import Flask, jsonify
13
14from i2p_apps.console.context import ConsoleContext
15
16
17def create_app(config: dict | None = None) -> Flask:
18 """Create the Flask console application."""
19 template_dir = os.path.join(os.path.dirname(__file__), "templates")
20 app = Flask(__name__, template_folder=template_dir)
21
22 if config:
23 app.config.update(config)
24
25 # Attach router context
26 if "CONSOLE_CONTEXT" not in app.config:
27 app.config["CONSOLE_CONTEXT"] = ConsoleContext()
28
29 # Health endpoint
30 @app.route("/health")
31 def health():
32 return jsonify({"status": "ok"})
33
34 # Register blueprints
35 from i2p_apps.console.routes.dashboard import bp as dashboard_bp
36 from i2p_apps.console.routes.api import bp as api_bp
37 from i2p_apps.console.routes.config import bp as config_bp
38 from i2p_apps.console.routes.content import bp as content_bp
39 from i2p_apps.console.routes.graphs import bp as graphs_bp
40 app.register_blueprint(dashboard_bp)
41 app.register_blueprint(api_bp)
42 app.register_blueprint(config_bp)
43 app.register_blueprint(content_bp)
44 app.register_blueprint(graphs_bp)
45
46 return app