from typing import List, Type from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from starlette.middleware.sessions import SessionMiddleware from starlette_wtf import CSRFProtectMiddleware from . import common from .sql import db from .paths import Paths # Add your paths below from .paths import pages from .paths import table from .paths import errors paths: List[Type[Paths]] = [ pages.MainPaths, table.TablePaths, errors.ErrorsPaths, ] # Initialize SQL database db.Base.metadata.create_all(bind=db.engine) # Create app app = FastAPI() # Mount static files server app.mount( '/static', StaticFiles(directory=common.static_dir), name='static', ) # Add paths for p in paths: p(app).add_paths() # Add WTForms CSRF protection middlewares app.add_middleware( SessionMiddleware, secret_key=common.settings.session_key, ) app.add_middleware( CSRFProtectMiddleware, csrf_secret=common.settings.csrf_key, )