123 lines
3.8 KiB
Python
123 lines
3.8 KiB
Python
import os
|
|
import datetime
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
app = FastAPI(title="Distribuirani Sustavi - FPMOZ")
|
|
|
|
SERVICE_NAME = os.getenv("SERVICE_NAME", "distribuirani-service")
|
|
LOG_LEVEL = os.getenv("LOG_LEVEL", "info")
|
|
WELCOME_MSG = os.getenv("WELCOME_MSG", "Pozdrav iz FPMOZ k3s clustera!")
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
def root():
|
|
return f"""<!DOCTYPE html>
|
|
<html lang="hr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{SERVICE_NAME}</title>
|
|
<style>
|
|
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
body {{
|
|
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
|
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
|
|
color: #e0e0e0;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}}
|
|
.container {{
|
|
text-align: center;
|
|
padding: 3rem;
|
|
background: rgba(255,255,255,0.05);
|
|
border-radius: 20px;
|
|
backdrop-filter: blur(10px);
|
|
border: 1px solid rgba(255,255,255,0.1);
|
|
max-width: 600px;
|
|
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
|
}}
|
|
h1 {{
|
|
font-size: 2.2rem;
|
|
background: linear-gradient(90deg, #00d2ff, #3a7bd5);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
margin-bottom: 1rem;
|
|
}}
|
|
.welcome {{
|
|
font-size: 1.3rem;
|
|
color: #a0d8ef;
|
|
margin-bottom: 2rem;
|
|
}}
|
|
.info {{
|
|
display: grid;
|
|
gap: 0.8rem;
|
|
text-align: left;
|
|
background: rgba(0,0,0,0.2);
|
|
padding: 1.5rem;
|
|
border-radius: 12px;
|
|
}}
|
|
.info-row {{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 0.4rem 0;
|
|
border-bottom: 1px solid rgba(255,255,255,0.05);
|
|
}}
|
|
.label {{ color: #888; }}
|
|
.value {{ color: #00d2ff; font-weight: 600; }}
|
|
.badge {{
|
|
display: inline-block;
|
|
margin-top: 1.5rem;
|
|
padding: 0.5rem 1.2rem;
|
|
background: linear-gradient(90deg, #00d2ff, #3a7bd5);
|
|
border-radius: 20px;
|
|
font-size: 0.85rem;
|
|
color: #fff;
|
|
font-weight: 600;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Distribuirani Sustavi</h1>
|
|
<p class="welcome">{WELCOME_MSG}</p>
|
|
<div class="info">
|
|
<div class="info-row">
|
|
<span class="label">Servis</span>
|
|
<span class="value">{SERVICE_NAME}</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">Hostname</span>
|
|
<span class="value">{os.getenv("HOSTNAME", "local")}</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">Log Level</span>
|
|
<span class="value">{LOG_LEVEL}</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">Vrijeme</span>
|
|
<span class="value">{datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")}</span>
|
|
</div>
|
|
</div>
|
|
<span class="badge">FPMOZ K3s Cluster • GitOps CI/CD</span>
|
|
</div>
|
|
</body>
|
|
</html>"""
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|
|
|
|
|
|
@app.get("/info")
|
|
def info():
|
|
return {
|
|
"service": SERVICE_NAME,
|
|
"hostname": os.getenv("HOSTNAME", "local"),
|
|
"log_level": LOG_LEVEL,
|
|
"welcome": WELCOME_MSG,
|
|
"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
} |