feat: finish readme and add swagger
This commit is contained in:
10
README.md
10
README.md
@@ -9,7 +9,8 @@ Initially designed to run directly on a raspberry pi, it has been containerized
|
||||
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
|
||||
sources compared to their stock APIs.
|
||||
sources compared to their stock APIs. Swagger is hosted at /swagger
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
@@ -46,9 +47,10 @@ The application will be available at `http://localhost:8000`
|
||||
|
||||
### Environment Variables
|
||||
|
||||
| Variable | Description | Default | Required |
|
||||
|-------------------|---------------------------------|---------|----------|
|
||||
| `FRONTEND_ENABLE` | Enable/disable the web frontend | `true` | No |
|
||||
| Variable | Description | Default | Required |
|
||||
|-------------------|------------------------------------------------------------|---------|----------|
|
||||
| `FRONTEND_ENABLE` | Enable/disable the web frontend | `true` | No |
|
||||
| `SHOW_SWAGGER` | Enable/disable Swagger API documentation at `/swagger` | `false` | No |
|
||||
|
||||
### Running with Docker Compose
|
||||
|
||||
|
||||
BIN
attachments/swagger.png
Normal file
BIN
attachments/swagger.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
14
main.py
14
main.py
@@ -15,7 +15,15 @@ from mta_sign_server.config.router import router as config_router
|
||||
|
||||
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(
|
||||
CORSMiddleware,
|
||||
allow_origins=['*']
|
||||
@@ -49,6 +57,10 @@ if frontend_enabled and static_dir.exists():
|
||||
@app.get("/{path:path}")
|
||||
async def serve_spa(path: str):
|
||||
"""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
|
||||
if file_path.exists() and file_path.is_file():
|
||||
return FileResponse(file_path)
|
||||
|
||||
Reference in New Issue
Block a user