Init
This commit is contained in:
57
backend/app/main.py
Normal file
57
backend/app/main.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import time
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.services.menu import build_menu
|
||||
from app.services.prices import prices_payload, random_price
|
||||
from app.settings import settings
|
||||
|
||||
START_TIME = time.time()
|
||||
|
||||
|
||||
def uptime() -> int:
|
||||
return int(time.time() - START_TIME)
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Cafetería API",
|
||||
description="Devuelve precios y el menú del día.",
|
||||
version="0.1.0",
|
||||
)
|
||||
|
||||
# Frontend and API will likely run on different ports; allow everything to keep the workshop simple.
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return {
|
||||
"status": "ok",
|
||||
"version": settings.app_version,
|
||||
"commit": settings.git_commit,
|
||||
"build": settings.build_number,
|
||||
"author": settings.commit_author,
|
||||
"uptime_seconds": uptime()
|
||||
}
|
||||
|
||||
|
||||
@app.get("/menu")
|
||||
def menu():
|
||||
return build_menu()
|
||||
|
||||
|
||||
@app.get("/prices")
|
||||
def prices():
|
||||
return prices_payload()
|
||||
|
||||
|
||||
@app.get("/prices/{item}")
|
||||
def price_for_item(item: str):
|
||||
return random_price(item)
|
||||
Reference in New Issue
Block a user