fix: add 404 support

This commit is contained in:
Alex Wellnitz 2024-09-25 16:04:09 +02:00
parent 1ea9bde1b6
commit cac2bbcc6f
2 changed files with 15 additions and 0 deletions

View File

@ -13,6 +13,13 @@ from fastapi import FastAPI, Form
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.responses import PlainTextResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from fastapi.exception_handlers import (
http_exception_handler,
request_validation_exception_handler,
)
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from starlette.responses import FileResponse, HTMLResponse
@ -52,6 +59,13 @@ def read_root():
index_path = os.path.join('templates', 'index.html')
return FileResponse(index_path)
@app.exception_handler(StarletteHTTPException)
async def custom_http_exception_handler(request, exc):
print(f"OMG! An HTTP error!: {repr(exc)}")
index_path = os.path.join('templates', '404.html')
return FileResponse(index_path)
@app.post("/sim/current_gear")
def simulate_current_gear(simcprofile: Annotated[str, Form()]):

View File

@ -1,4 +1,5 @@
.gearcontainer {
display: none;
width: 100%;
height: 100%;
border: 1px solid;