Untitled

mail@pastecode.io avatar
unknown
python
5 months ago
1.1 kB
5
Indexable
Never
from fastapi import FastAPI, Depends
from fastapi.middleware.cors import CORSMiddleware
import requests

ip_domain = '172.18.60.90'
port_domain = '443'
basic_auth = 'Basic b2RzbW9iaWxlOiQyYSQxMCRPaE1pc0H5UTdYTVlOall2Z0tidWh1QTNES1RzTmN0aHZKSU5wb1RDd1ZGZUdHeTJGcUh3S'

app = FastAPI()

origins = [
    "*"
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"]
)

def perform_get_request():
    url = f"https://{ip_domain}:{port_domain}/service/reop/summary"
    headers = {
        "Authorization": basic_auth
    }
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        return data
    except Exception as e:
        return {"error": str(e)}

@app.get("/health")
def health_check() -> dict[str, str]:
    return {"status": "UP"}

@app.get("/service/reop/summary")
def getReop() -> dict[str, str]:
    response_data = perform_get_request()
    return response_data

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)