-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
33 lines (24 loc) · 802 Bytes
/
server.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
import logging
import socket
import time
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from utils.router import load_routes
hostname = socket.gethostname()
logging.basicConfig(
level=logging.DEBUG, # Set the desired logging level
format=f'%(asctime)s [%(levelname)s] {hostname} %(message)s',
handlers=[
logging.StreamHandler()
]
)
app = FastAPI()
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
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
app.mount("/assets", StaticFiles(directory="templates/assets"), name="assets")
load_routes(app, 'routes')