2024-02-19 20:43:39 +09:00
|
|
|
from fastapi import FastAPI, Request
|
|
|
|
from fastapi.responses import HTMLResponse
|
2024-02-19 12:21:12 +09:00
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
2024-02-19 20:43:39 +09:00
|
|
|
from fastapi.templating import Jinja2Templates
|
2024-02-19 12:21:12 +09:00
|
|
|
|
|
|
|
from src.database import engine
|
|
|
|
from src import models
|
|
|
|
from src.routes.url import url_route
|
|
|
|
|
|
|
|
|
|
|
|
models.Base.metadata.create_all(bind=engine)
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
2024-02-19 20:43:39 +09:00
|
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
|
2024-02-19 12:21:12 +09:00
|
|
|
origins = [
|
|
|
|
"*",
|
|
|
|
]
|
|
|
|
|
|
|
|
app.add_middleware(
|
|
|
|
CORSMiddleware,
|
|
|
|
allow_origins=origins,
|
|
|
|
allow_credentials=True,
|
|
|
|
allow_methods=["*"],
|
|
|
|
allow_headers=["*"],
|
|
|
|
)
|
|
|
|
|
2024-02-19 20:43:39 +09:00
|
|
|
app.mount("/static", StaticFiles(directory="./static"), name="static")
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
|
|
def index(request: Request):
|
|
|
|
return templates.TemplateResponse(request=request, name="index.html")
|
2024-02-19 12:21:12 +09:00
|
|
|
|
2024-02-19 20:43:39 +09:00
|
|
|
|
|
|
|
@app.get("/about", response_class=HTMLResponse)
|
|
|
|
def about(request: Request):
|
|
|
|
return templates.TemplateResponse(request=request, name="about.html")
|
|
|
|
|
|
|
|
|
|
|
|
app.include_router(url_route.routes)
|