33 lines
777 B
Python
33 lines
777 B
Python
import os
|
|
|
|
import yaml
|
|
from flask import Flask
|
|
|
|
from tofu_api.api import TofuApiBlueprint
|
|
from tofu_api.config import DefaultConfig
|
|
|
|
|
|
def create_app() -> Flask:
|
|
"""
|
|
App factory, returns a Flask app object.
|
|
"""
|
|
# Set instance path to the project root directory
|
|
project_root_dir = os.path.abspath('.')
|
|
|
|
# Create and configure the app
|
|
app = Flask(
|
|
'tofu_api',
|
|
instance_path=project_root_dir,
|
|
instance_relative_config=True,
|
|
)
|
|
app.config.from_object(DefaultConfig)
|
|
|
|
# Load app configuration from YAML file
|
|
app.config.from_file(os.getenv('FLASK_CONFIG_FILE', default='config.yml'), load=yaml.safe_load)
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(TofuApiBlueprint())
|
|
|
|
# Return WSGI app
|
|
return app
|