-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (39 loc) · 1.64 KB
/
Copy pathapp.py
File metadata and controls
46 lines (39 loc) · 1.64 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
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from middlewares.middleware import dispatch
from routers.auth.auth import router as auth_router
from routers.features.build_video import router as build_video_router
from routers.features.videos import router as get_videos_router
from routers.features.payments import router as get_payments_router
from database import create_db_and_tables
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["Authorization", "Content-Type"],
)
# Serve static video files at /api/video path
app.mount("/api/video", StaticFiles(directory="static/videos"), name="video")
# Include routers with '/api' prefix for all endpoints
app.include_router(auth_router, prefix="/api/auth", tags=["auth"])
app.include_router(build_video_router, prefix="/api/build_video", tags=["build_video"])
app.include_router(get_videos_router, prefix="/api/get_videos", tags=["get_videos"])
app.include_router(get_payments_router,prefix="/api/payments", tags=["payments"])
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
print(f"Incoming request: {request.url.path}")
if request.method == "OPTIONS":
return await call_next(request)
if request.url.path.startswith('/api/build_video/process'):
dispatch(request=request)
response = await call_next(request)
return response
@app.get("/api/")
async def health():
return {"Hello": "World"}