-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (57 loc) · 1.83 KB
/
app.py
File metadata and controls
65 lines (57 loc) · 1.83 KB
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
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import JSONResponse
import logging
import uvicorn
import time
import traceback
# from api.endpoints import sense_concurrency
# Import routers
#from api.endpoints import router as verifier_router
from api.endpoints import register_endpoints, sense_concurrency
# Setup logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger("face-verifier-app")
# App instance
app = FastAPI(
title="Face Verification API",
description="Optimized endpoints for face verification and document validation.",
version="2.0.0",
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # You can restrict later to your domain
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount routers
#app.include_router(verifier_router, prefix="/api/v1")
register_endpoints(app)
# Middleware for logging requests and timing
@app.middleware("http")
async def log_requests(request: Request, call_next):
start_time = time.time()
try:
response = await call_next(request)
except Exception as e:
logger.error(f"Unhandled error: {e}\n{traceback.format_exc()}")
return JSONResponse(
status_code=500,
content={"status": "error", "message": "Internal server error"},
)
process_time = (time.time() - start_time) * 1000
logger.info(
f"{request.method} {request.url.path} "
f"completed in {process_time:.2f}ms "
f"status={response.status_code}"
)
return response
# Health check endpoint
@app.get("/health", tags=["System"])
async def health_check():
return {"status": "ok", "message": "Face Verification API is running"}