50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
from api import router as api_router
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env")
|
|
production: bool = False
|
|
staging: bool = False
|
|
|
|
settings = Settings()
|
|
|
|
|
|
app = FastAPI(
|
|
title="ArithMedic",
|
|
description="LLM-Agent First, Open-Source Medical Calculations.",
|
|
version="0.1.0",
|
|
)
|
|
|
|
if settings.production:
|
|
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="127.0.0.1")
|
|
app.add_middleware(
|
|
TrustedHostMiddleware,
|
|
allowed_hosts=["arithmedic.eu", "www.arithmedic.eu", "arithmedic.org", "www.arithmedic.org", "arithmedic.net", "www.arithmedic.net", "arithmedic.nu", "www.arithmedic.nu", "arithmedic.se", "www.arithmedic.se", "127.0.0.1", "localhost", "stage.arithmedic.eu"],
|
|
)
|
|
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["GET", "POST", "OPTIONS"],
|
|
allow_headers=["Content-Type"],
|
|
)
|
|
|
|
app.include_router(api_router)
|
|
|
|
templates = Jinja2Templates(directory="templates")
|
|
templates.env.globals["staging"] = settings.staging
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
|
|
def index(request: Request) -> HTMLResponse:
|
|
return templates.TemplateResponse(request, "index.html")
|