-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.47 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
import time
from pathlib import Path
from fastapi import FastAPI, APIRouter, Request, Depends
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session
from starlette.middleware.cors import CORSMiddleware
from app import crud
from app.api import deps
from app.api.api_v1.api import api_router
from app.core.config import settings
BASE_PATH = Path(__file__).resolve().parent
TEMPLATES = Jinja2Templates(directory=str(BASE_PATH / "templates"))
root_router = APIRouter()
app = FastAPI(title="Auth Service API", openapi_url=f"{settings.API_V1_STR}/openapi.json")
origins = [
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@root_router.get("/", status_code=200)
def root(
request: Request
) -> dict:
"""
Root GET
"""
return {"message": "Welcome to auth service!."}
@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.include_router(api_router, prefix=settings.API_V1_STR)
app.include_router(root_router)
if __name__ == "__main__":
# Use this for debugging purposes only
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="debug")