first commit
This commit is contained in:
51
service_app/app.py
Normal file
51
service_app/app.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import uvicorn
|
||||
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from middlewares.token_middleware import AuthHeaderMiddleware
|
||||
from application.create_file import create_app
|
||||
from handlers_exception import (
|
||||
exception_handler_http,
|
||||
exception_handler_exception,
|
||||
)
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from prometheus_client import Counter, Histogram
|
||||
|
||||
|
||||
app = create_app()
|
||||
Instrumentator().instrument(app=app).expose(app=app)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
**{
|
||||
"allow_origins": ["*"],
|
||||
"allow_credentials": True,
|
||||
"allow_methods": ["*"],
|
||||
"allow_headers": ["*"],
|
||||
}
|
||||
)
|
||||
app.add_middleware(AuthHeaderMiddleware)
|
||||
|
||||
app.add_exception_handler(HTTPException, exception_handler_http)
|
||||
app.add_exception_handler(Exception, exception_handler_exception)
|
||||
|
||||
# # Define a counter metric
|
||||
# REQUESTS_COUNT = Counter(
|
||||
# "requests_total", "Total number of requests", ["method", "endpoint", "status_code"]
|
||||
# )
|
||||
# # Define a histogram metric
|
||||
# REQUESTS_TIME = Histogram("requests_time", "Request processing time", ["method", "endpoint"])
|
||||
# api_request_summary = Histogram("api_request_summary", "Request processing time", ["method", "endpoint"])
|
||||
# api_request_counter = Counter("api_request_counter", "Request processing time", ["method", "endpoint", "http_status"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn_config = {
|
||||
"app": "app:app",
|
||||
"host": "0.0.0.0",
|
||||
"port": 41575,
|
||||
"log_level": "info",
|
||||
"reload": True,
|
||||
}
|
||||
uvicorn.Server(uvicorn.Config(**uvicorn_config)).run()
|
||||
Reference in New Issue
Block a user