-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (48 loc) · 1.56 KB
/
main.py
File metadata and controls
59 lines (48 loc) · 1.56 KB
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
51
52
53
54
55
56
57
58
59
import dotenv
dotenv.load_dotenv()
from fastapi import Depends, FastAPI, status
from fastapi.middleware.cors import CORSMiddleware
from api import dependencies, settings, tags
from api.database import Base, engine
from api.endpoints import auth, auth_get, files, job_update, jobs
from api.exceptions import register_exception_handlers
from api.schemas.common import MessageResponse
app = FastAPI(openapi_tags=tags.tags_metadata)
if settings.frontend_url:
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.frontend_url],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(
files.router,
tags=["Files"],
dependencies=[Depends(dependencies.current_user_global_dep)],
)
app.include_router(
jobs.router,
tags=["Jobs"],
dependencies=[Depends(dependencies.current_user_global_dep)],
)
if settings.auth:
app.include_router(auth.router, tags=["Authentication"])
app.include_router(auth_get.router, tags=["Authentication"])
# private endpoint for worker-facing API
app.include_router(job_update.router, tags=["_Internal"])
register_exception_handlers(app)
@app.get(
"/",
response_model=str,
status_code=status.HTTP_200_OK,
description="Welcome message for the DECODE OpenCloud User-facing API",
responses={
200: {"description": "Welcome message", "model": str}
}
)
async def root() -> str:
return "Welcome to the DECODE OpenCloud User-facing API"
@app.on_event("startup")
def on_startup() -> None:
Base.metadata.create_all(bind=engine)