Files
alfieking.dev/src/wsgi.py
2026-01-18 23:21:44 +00:00

64 lines
1.7 KiB
Python

# Imports
from flask import Flask, render_template, send_file
from flask_session import Session
from dotenv import load_dotenv
from os import getenv as env
import logging
import src.routes.error_handlers
import src.routes.dynamic_routes
# Load env
load_dotenv()
# Create logger
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
stream_handler.setLevel(logging.INFO)
file_handler = logging.FileHandler(filename='app.log')
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
file_handler.setLevel(logging.DEBUG)
# Add handlers to the logger
log = logging.getLogger()
log.setLevel(logging.DEBUG)
log.addHandler(stream_handler)
log.addHandler(file_handler)
log.info("Logging initialized")
# Create flask app
app = Flask(
__name__,
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
static_folder=env('STATIC_FOLDER', default='../static')
)
# Configure sessions
app.config["SESSION_PERMANENT"] = True
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
# Load routes
app.register_blueprint(src.routes.error_handlers.bp, url_prefix='/error')
app.register_blueprint(src.routes.dynamic_routes.bp, url_prefix='/')
# Generic routes
@app.route('/')
def index():
return render_template('index.html')
@app.route('/favicon.ico')
def favicon():
return send_file('../static/content/other/favicon.ico')
@app.route('/robots.txt')
def robots():
return send_file('../static/content/other/robots.txt')
# Route for sitemap.xml
@app.route('/sitemap.xml')
def sitemap():
return send_file('../static/content/other/sitemap.xml')