feat: finish readme and add swagger

This commit is contained in:
Lucas Oskorep
2026-01-20 22:50:05 -05:00
parent dc8a2c9d3e
commit 33c7a108e2
3 changed files with 19 additions and 5 deletions

View File

@@ -9,7 +9,8 @@ Initially designed to run directly on a raspberry pi, it has been containerized
podman or docker! podman or docker!
Additionally, this can be run without the frontend in case you just wanted a slightly more sane way to query MTA's data Additionally, this can be run without the frontend in case you just wanted a slightly more sane way to query MTA's data
sources compared to their stock APIs. sources compared to their stock APIs. Swagger is hosted at /swagger
![swagger.png](attachments/swagger.png)
## Features ## Features
@@ -46,9 +47,10 @@ The application will be available at `http://localhost:8000`
### Environment Variables ### Environment Variables
| Variable | Description | Default | Required | | Variable | Description | Default | Required |
|-------------------|---------------------------------|---------|----------| |-------------------|------------------------------------------------------------|---------|----------|
| `FRONTEND_ENABLE` | Enable/disable the web frontend | `true` | No | | `FRONTEND_ENABLE` | Enable/disable the web frontend | `true` | No |
| `SHOW_SWAGGER` | Enable/disable Swagger API documentation at `/swagger` | `false` | No |
### Running with Docker Compose ### Running with Docker Compose

BIN
attachments/swagger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

14
main.py
View File

@@ -15,7 +15,15 @@ from mta_sign_server.config.router import router as config_router
load_dotenv() load_dotenv()
app = FastAPI() # Setup Swagger documentation
show_swagger = os.getenv("SHOW_SWAGGER", "false").lower() in ("true", "1", "yes")
swagger_config = {
"docs_url": "/swagger" if show_swagger else None,
"redoc_url": None,
"openapi_url": "/openapi.json" if show_swagger else None,
}
app = FastAPI(**swagger_config)
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=['*'] allow_origins=['*']
@@ -49,6 +57,10 @@ if frontend_enabled and static_dir.exists():
@app.get("/{path:path}") @app.get("/{path:path}")
async def serve_spa(path: str): async def serve_spa(path: str):
"""Serve static files or fall back to index.html for SPA routing""" """Serve static files or fall back to index.html for SPA routing"""
# Exclude API and documentation routes from SPA fallback
if path.startswith(("api/", "swagger", "openapi", "redoc", "docs")):
return {"error": "Not found"}
file_path = static_dir / path file_path = static_dir / path
if file_path.exists() and file_path.is_file(): if file_path.exists() and file_path.is_file():
return FileResponse(file_path) return FileResponse(file_path)