tmpl-fastapi/app/main.py

43 lines
858 B
Python
Raw Normal View History

from typing import List, Type
2023-02-20 11:09:43 +03:00
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
2023-02-20 11:09:43 +03:00
from starlette.middleware.sessions import SessionMiddleware
from starlette_wtf import CSRFProtectMiddleware
2023-02-19 15:19:18 +03:00
from . import common
2023-02-20 11:09:43 +03:00
from .sql import db
# Add your paths here
from .paths.paths import Paths
from .paths import pages
2023-02-20 11:09:43 +03:00
from .paths import table
from .paths import errors
paths: List[Type[Paths]] = [
pages.MainPaths,
2023-02-20 11:09:43 +03:00
table.TablePaths,
errors.ErrorsPaths,
]
2023-02-20 11:09:43 +03:00
db.Base.metadata.create_all(bind=db.engine)
app = FastAPI()
app.mount(
'/static',
2023-02-19 15:19:18 +03:00
StaticFiles(directory=common.static_dir),
name='static',
)
for p in paths:
p(app).add_paths()
2023-02-20 11:09:43 +03:00
app.add_middleware(
SessionMiddleware,
secret_key=common.settings.session_key,
)
app.add_middleware(
CSRFProtectMiddleware,
csrf_secret=common.settings.csrf_key,
)