bettersight-statement-extra.../backend/app.py

47 lines
1.4 KiB
Python

# Flask app factory - registers blueprints, wires config from dependencies.py.
import os
from flask import Flask, render_template
import dependencies
from routes.extraction import extraction_bp
from routes.health import health_bp
def create_app():
"""
Builds and configures the Flask application.
Data flow:
(no input)
returns (Flask) - the configured app, routes registered, ready to run
Steps:
1. Create the Flask instance (template_folder still points at the
existing templates/ directory - the frontend restructure into
its own Vue app is a later stage; this app keeps serving the
current UI unchanged in the meantime)
2. Apply config from dependencies.py (upload size cap)
3. Register the extraction and health blueprints
4. Keep the "/" route serving today's UI, unchanged
"""
app = Flask(__name__, template_folder="../templates")
app.config["MAX_CONTENT_LENGTH"] = dependencies.MAX_CONTENT_LENGTH
app.register_blueprint(extraction_bp)
app.register_blueprint(health_bp)
@app.route("/")
def index():
return render_template("index.html")
return app
app = create_app()
if __name__ == "__main__":
os.makedirs(dependencies.UPLOAD_FOLDER, exist_ok=True)
os.makedirs(dependencies.OUTPUT_FOLDER, exist_ok=True)
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port, debug=False, threaded=True)