60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""
|
|
FastAPI Application Entry Point
|
|
|
|
This module initializes and configures the FastAPI application with:
|
|
- CORS middleware for cross-origin requests
|
|
- Request timing middleware for performance monitoring
|
|
- Custom exception handlers for consistent error responses
|
|
- Prometheus instrumentation for metrics
|
|
- API routers for endpoint organization
|
|
"""
|
|
|
|
import uvicorn
|
|
from arrow import now
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse, RedirectResponse
|
|
|
|
|
|
app = FastAPI(
|
|
title="Dummy api",
|
|
description="Api from test purposes",
|
|
default_response_class=JSONResponse,
|
|
) # Initialize FastAPI app
|
|
|
|
|
|
@app.get(path="/current/date", summary="Receive token via device id and encrypt data")
|
|
def receive_api_current_date():
|
|
"""
|
|
Output
|
|
* utc_string: str
|
|
* utc_float_timestamp: float
|
|
* utc_timezone: Optional[str]
|
|
* current_string: str
|
|
* current_float_timestamp: float
|
|
* current_timezone: Optional[str]
|
|
* source: str
|
|
* source_address: str
|
|
"""
|
|
return dict(
|
|
utc_string=str(now()),
|
|
utc_float_timestamp=now().float_timestamp,
|
|
utc_timezone=now().tzname(),
|
|
current_string=now().shift(hours=+3).__str__(),
|
|
current_float_timestamp=now().shift(hours=+3).float_timestamp,
|
|
current_timezone="GMT +3",
|
|
source="TITLE",
|
|
source_address="Ankara/Turkey",
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
# Run the application with Uvicorn
|
|
config_dict = dict(
|
|
app="app:app",
|
|
host = "0.0.0.0",
|
|
port = 8000,
|
|
log_level = "info",
|
|
reload = True,
|
|
)
|
|
uvicorn.Server(uvicorn.Config(**config_dict)).run()
|