-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
50 lines (37 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi.middleware.cors import CORSMiddleware
from app.routes import auth
origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:3000",
]
app = FastAPI()
app.mount(
"/public/static", StaticFiles(directory="public/static"), name="static"
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.public)
app.include_router(auth.protected)
templates = Jinja2Templates(directory="public/templates")
@app.exception_handler(404)
def page_not_found(request: Request, e):
return templates.TemplateResponse("404.html", {"request": request})
@app.exception_handler(405)
def action_not_allowed(request: Request, e):
return templates.TemplateResponse("405.html", {"request": request})
@app.get("/")
def root_get(request: Request):
return templates.TemplateResponse("404.html", {"request": request})
@app.post("/")
def root_post(request: Request):
return templates.TemplateResponse("404.html", {"request": request})