Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch-all route applies only to front-end assets #890

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The types of changes are:
* Webserver dependencies now come as a standard part of the package [#881](https://github.com/ethyca/fides/pull/881)
* Initial configuration wizard UI view
* Refactored step & form results management to use Redux Toolkit slice.
* The "catch-all" route now applies to front-end asset requests only [#890](https://github.com/ethyca/fides/pull/890)

### Docs

Expand Down
21 changes: 8 additions & 13 deletions src/fidesapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,20 @@ def read_index() -> Response:
return FileResponse(WEBAPP_INDEX)


@app.get("/{catchall:path}", response_class=FileResponse, tags=["Default"])
@app.get(
str(WEBAPP_DIRECTORY) + "/{catchall:path}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allisonking Does this satisfy your requirement for a front-end "catch-all", or is there a better way to specify this path?

response_class=FileResponse,
tags=["Default"],
)
def read_other_paths(request: Request) -> FileResponse:
"""
Return related frontend files. Adapted from https://github.com/tiangolo/fastapi/issues/130
Return related frontend files.
"""
# check first if requested file exists (for frontend assets)

path = request.path_params["catchall"]
file = WEBAPP_DIRECTORY / Path(path)
if file.exists():
return FileResponse(file)

# raise 404 for anything that should be backend endpoint but we can't find it
if path.startswith(API_PREFIX[1:]):
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Item not found"
)

# otherwise return the index
return FileResponse(WEBAPP_INDEX)
return FileResponse(file) if file.exists() else FileResponse(WEBAPP_INDEX)


def start_webserver() -> None:
Expand Down