generated from 0xTheProDev/fastapi-clean-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (54 loc) · 1.68 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Main application module."""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from configs.Environment import get_environment_variables
from configs.Logging import configure_logging
from configs.OpenAPI import configure_openapi
from configs.queue_dependencies import get_queue_service
from routers.v1.ActivityRouter import (
router as activity_router,
)
from routers.v1.AuthRouter import router as auth_router
from routers.v1.DocumentRouter import (
router as document_router,
)
from routers.v1.MomentRouter import router as moment_router
from routers.v1.NoteRouter import router as note_router
from routers.v1.TaskRouter import router as task_router
from routers.v1.TopicRouter import router as topic_router
from utils.middleware.request_logging import (
RequestLoggingMiddleware,
)
# Get environment variables
env = get_environment_variables()
# Configure logging
configure_logging()
# Create FastAPI app
app = FastAPI()
# Configure OpenAPI
configure_openapi(app)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Add request logging middleware
app.add_middleware(RequestLoggingMiddleware)
# Add routers
app.include_router(auth_router)
app.include_router(activity_router)
app.include_router(document_router)
app.include_router(moment_router)
app.include_router(note_router)
app.include_router(task_router)
app.include_router(topic_router)
# Add dependencies
def get_queue_service_override():
"""Override QueueService dependency."""
return get_queue_service()
app.dependency_overrides[
get_queue_service
] = get_queue_service_override