Build Flask WAF log converter app
This commit is contained in:
28
app/__init__.py
Normal file
28
app/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from pathlib import Path
|
||||
|
||||
from flask import Flask, flash, render_template
|
||||
from werkzeug.exceptions import RequestEntityTooLarge
|
||||
|
||||
from app.config import Config
|
||||
from app.routes import main_blueprint
|
||||
|
||||
|
||||
def create_app(config_class: type[Config] = Config) -> Flask:
|
||||
"""Application factory used by Flask and Gunicorn."""
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
app.config.from_object(config_class)
|
||||
|
||||
output_dir = Path(app.config["OUTPUT_DIRECTORY"])
|
||||
if not output_dir.is_absolute():
|
||||
output_dir = Path(app.instance_path) / output_dir
|
||||
app.config["OUTPUT_DIRECTORY"] = output_dir
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
app.register_blueprint(main_blueprint)
|
||||
|
||||
@app.errorhandler(RequestEntityTooLarge)
|
||||
def handle_file_too_large(_error):
|
||||
flash("The uploaded file is too large.", "danger")
|
||||
return render_template("index.html"), 413
|
||||
|
||||
return app
|
||||
Reference in New Issue
Block a user