-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (28 loc) · 881 Bytes
/
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
from fastapi import FastAPI, Depends
from starlette.middleware.cors import CORSMiddleware
from starlette.staticfiles import StaticFiles
from auth import auth
from auth.dependencies import get_current_user, login_redirect
from auth.models import User
from config.variables import set_up
app = FastAPI()
config = set_up()
origins = [
f"{config['protocol']}{config['domain']}",
f"{config['protocol']}{config['domain']}:{config['port']}"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.router)
if config['debug']:
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
def home(current_user: User = Depends(get_current_user)):
if not current_user:
return login_redirect("/")
return current_user