-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
39 lines (32 loc) · 883 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
38
39
from fastapi import FastAPI
from starlette.middleware.base import BaseHTTPMiddleware
from starlette_context import plugins
from starlette_context.middleware import RawContextMiddleware
from api.v1.routing import RoutingV1
from middlewares import RequestPreProcessor, AuthenticationContext
# Global app variable
app = FastAPI()
# Touch Pydantic Encoders
from core import json
json.ENCODERS_BY_TYPE
# Middlewares
"""
Order of precedence is important here.
1. Request Middleware
2. Decyrption Middleware
3. Context Plugin Middleware
"""
app.add_middleware(BaseHTTPMiddleware, dispatch=RequestPreProcessor())
app.add_middleware(
RawContextMiddleware,
plugins=(
AuthenticationContext(),
plugins.RequestIdPlugin(),
plugins.CorrelationIdPlugin(),
),
)
# Routing Information
"""
Add versioned routing information here
"""
RoutingV1(app).map_urls()