Skip to content

Commit

Permalink
fix responses and disable root path
Browse files Browse the repository at this point in the history
  • Loading branch information
elsholz committed Dec 28, 2023
1 parent ced18af commit c3466ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions api/code/metroplanner_api/metroplanner_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
from . import responses


app = FastAPI(servers=[{"url": ENV.api_url, "description": "CloudFront URL"}])
app = FastAPI(
servers=[{"url": ENV.api_url, "description": "CloudFront URL"}],
root_path_in_servers=False,
)

from . import v1

router = APIRouter(prefix="/api")
router = APIRouter(prefix="/dev/api")
router.include_router(v1.router)

app.include_router(router)
Expand Down
14 changes: 7 additions & 7 deletions api/code/metroplanner_api/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ def bad_request_400():


def unauthorized_401():
raise HTTPException(statusCode=401, body="Unauthorized")
raise HTTPException(status_code=401, body="Unauthorized")


def forbidden_403():
raise HTTPException(statusCode=403, body="Forbidden")
raise HTTPException(status_code=403, body="Forbidden")


# using 410 over 404 as a workaround, since AWS CloudFront will return index.html on 404 errors
def gone_410():
raise HTTPException(statusCode=410, body="Gone")
raise HTTPException(status_code=410, body="Gone")


def method_not_allowed_405():
raise HTTPException(statusCode=405, body="Method Not Allowed")
raise HTTPException(status_code=405, body="Method Not Allowed")


def not_acceptable_406():
raise HTTPException(statusCode=406, body="Not Acceptable")
raise HTTPException(status_code=406, body="Not Acceptable")


### 5xx
def internal_server_error_500():
raise HTTPException(statusCode=500, body="Internal Server Error")
raise HTTPException(status_code=500, body="Internal Server Error")


def not_implemented_501():
raise HTTPException(statusCode=501, body="Not Implemented")
raise HTTPException(status_code=501, body="Not Implemented")

0 comments on commit c3466ac

Please sign in to comment.