From cac2bbcc6f9338df849c9dd0c5dd3ed33671f755 Mon Sep 17 00:00:00 2001 From: Alex Wellnitz Date: Wed, 25 Sep 2024 16:04:09 +0200 Subject: [PATCH] fix: add 404 support --- backend/main.py | 14 ++++++++++++++ .../src/app/ui/snippets/gear-parser.module.css | 1 + 2 files changed, 15 insertions(+) diff --git a/backend/main.py b/backend/main.py index 5ed4232..b05dc27 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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()]): diff --git a/frontend/src/app/ui/snippets/gear-parser.module.css b/frontend/src/app/ui/snippets/gear-parser.module.css index ebf8bf0..7be3efa 100644 --- a/frontend/src/app/ui/snippets/gear-parser.module.css +++ b/frontend/src/app/ui/snippets/gear-parser.module.css @@ -1,4 +1,5 @@ .gearcontainer { + display: none; width: 100%; height: 100%; border: 1px solid;