-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.py
36 lines (28 loc) · 812 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
import os
import time
from typing import Any, Callable
from fastapi import FastAPI, Request
from cloudrunfastapi import __project_id__, __version__
from cloudrunfastapi.routers import auth, health, item, user
os.environ["TZ"] = "UTC"
#
# create the api
#
api = FastAPI(title=f"Cloud Run FastAPI: {__project_id__}", version=__version__)
#
# middleware
#
@api.middleware("http")
async def add_process_time_header(request: Request, call_next: Callable) -> Any:
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
#
# set routers
#
api.include_router(health.router)
api.include_router(auth.router)
api.include_router(user.router)
api.include_router(item.router)