2023-02-18 21:25:47 +04:00
|
|
|
from typing import List, Type
|
2023-02-20 12:09:43 +04:00
|
|
|
|
2023-02-18 20:01:13 +04:00
|
|
|
from fastapi import FastAPI
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
2023-02-20 12:09:43 +04:00
|
|
|
from starlette.middleware.sessions import SessionMiddleware
|
|
|
|
from starlette_wtf import CSRFProtectMiddleware
|
|
|
|
|
2023-02-19 16:19:18 +04:00
|
|
|
from . import common
|
2023-02-27 20:11:55 +04:00
|
|
|
from . import sql
|
2023-02-18 21:25:47 +04:00
|
|
|
|
2023-02-20 12:41:29 +04:00
|
|
|
from .paths import Paths
|
|
|
|
# Add your paths below
|
2023-02-19 16:27:55 +04:00
|
|
|
from .paths import pages
|
2023-02-20 12:09:43 +04:00
|
|
|
from .paths import table
|
2023-02-19 16:27:55 +04:00
|
|
|
from .paths import errors
|
2023-02-18 21:25:47 +04:00
|
|
|
|
|
|
|
paths: List[Type[Paths]] = [
|
|
|
|
pages.MainPaths,
|
2023-02-20 12:09:43 +04:00
|
|
|
table.TablePaths,
|
2023-02-18 21:25:47 +04:00
|
|
|
errors.ErrorsPaths,
|
|
|
|
]
|
2023-02-18 20:01:13 +04:00
|
|
|
|
|
|
|
|
2023-02-27 19:05:04 +04:00
|
|
|
# Initialize SQL database
|
2023-02-27 20:11:55 +04:00
|
|
|
sql.Base.metadata.create_all(bind=sql.engine)
|
2023-02-27 19:05:04 +04:00
|
|
|
|
|
|
|
# Create app
|
2023-02-18 20:01:13 +04:00
|
|
|
app = FastAPI()
|
2023-02-27 19:05:04 +04:00
|
|
|
|
|
|
|
# Mount static files server
|
2023-02-18 20:01:13 +04:00
|
|
|
app.mount(
|
|
|
|
'/static',
|
2023-02-19 16:19:18 +04:00
|
|
|
StaticFiles(directory=common.static_dir),
|
2023-02-18 20:01:13 +04:00
|
|
|
name='static',
|
|
|
|
)
|
2023-02-27 19:05:04 +04:00
|
|
|
|
|
|
|
# Add paths
|
2023-02-18 21:25:47 +04:00
|
|
|
for p in paths:
|
|
|
|
p(app).add_paths()
|
2023-02-20 12:09:43 +04:00
|
|
|
|
2023-02-27 19:05:04 +04:00
|
|
|
# Add WTForms CSRF protection middlewares
|
2023-02-20 12:09:43 +04:00
|
|
|
app.add_middleware(
|
|
|
|
SessionMiddleware,
|
2023-03-24 19:00:31 +04:00
|
|
|
secret_key=common.settings.session_key,
|
2023-02-20 12:09:43 +04:00
|
|
|
)
|
|
|
|
app.add_middleware(
|
|
|
|
CSRFProtectMiddleware,
|
2023-03-24 19:00:31 +04:00
|
|
|
csrf_secret=common.settings.csrf_key,
|
2023-02-20 12:09:43 +04:00
|
|
|
)
|