RE: Fix /api/v1 prefix consistency and add a root resource to the REST API - #112
Merged
Merged
Conversation
A request to the bare server root (http://host:port/ or the reverse-proxy
root http://host:port/{prefix}/) previously returned 404, because all
resources are mounted under the /api/v1 prefix. Register a lightweight
route at "/" that issues a 302 redirect to the home endpoint, keeping the
deployment (reverse-proxy) prefix in the generated Location so clients
stay under the proxy path.
- fsdb_rest_api.py: add _register_root_redirect() helper that maps the
root path to home(prefix=deploy_prefix) and wire it into rest_api() so
both the fsdb_rest_api CLI and the WSGI entrypoint (wsgi.py) expose the
redirect, honoring the --api-prefix / API_PREFIX value.
- test_rest_api_server.py: add RootRedirectTests covering the no-prefix
and /plantdb-prefix cases (asserting the 302 and exact Location header)
plus a follow-redirect check that lands on the Home payload.
- Remove leading spaces before `>>>` prompts to clean up doctest formatting in `urls.py`
- Update `refresh` signature to `def refresh(scan_id: str | None = None, **kwargs) -> str` and adjust its docstring to "str or None, optional" - Insert a blank line after the `urllib` import for consistency - Remove the stray blank line preceding the `refresh` definition - Reformat parameter indentation in `fileset_metadata`, `file_metadata`, `image`, `pointcloud`, and `mesh` for clearer readability - Minor docstring wording updates (e.g., `key : str or None, optional`)
jlegrand62
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Problem
Two related issues in the PlantDB REST API:
/api/v1prefixing. Endpoint paths and the URLs embedded in server responses were not consistently including the/api/v1mount prefix, and there was no clean separation between the API version prefix and a deployment (reverse-proxy) path prefix.http://host:port/, orhttp://host:port/{prefix}/behind a proxy) returned404, because all resources are mounted under/api/v1.Solution
Introduce two distinct prefix concepts and thread them everywhere:
API_PREFIX = "/api/v1"— always present, shared truth. The app mounts at/api/v1only.deploy_prefix, e.g./plantdb) — a runtime per-server/per-client constant for reverse-proxy deployments, used only to generate external-facing URLs in responses.Server
api_endpoints: the@api_prefixdecorator now composes<deploy_prefix>/api/v1/<endpoint>(with proper sanitization) and theHomeresource builds its endpoint map via these builders.fsdb_rest_api/wsgi: mount at/api/v1always;deploy_prefixreplaces the deprecatedapi_prefixparam; the--api-prefix/API_PREFIXvalue is honored.get_scan_info/get_scan_data) and_get_colmap_camera_modelthread the prefix into every generated URL (archive, thumbnail, filesUri, camera poses). This fixes two bugs where camera-pose URLs and the nestedget_scan_infooutput lost the prefix.302redirect at/to the home endpoint, keeping the deployment prefix in theLocationheader so clients stay under the proxy path.Client
PlantDBClientstoresself.prefixand threads it into everyapi_endpoints.*call.login_url,scan_url,scan_image_url, …) build fully-prefixed URLs;plantdb_url()now returns the server root including the deployment prefix but not/api/v1.Tests
test_api_endpoints.py— deployment-prefix composition across all endpoint builders (78 subtests).test_scan_services.py— prefix threading through scan info/data services.test_rest_api_deploy_prefix.py— server responses embed the deployment prefix (Homemap,ScansTable,Scan).test_rest_api_server.py— root-redirect tests (no-prefix and/plantdbcases, exactLocation, follow-redirect).test_rest_api.py— updated client URL assertions for/api/v1and the rootplantdb_urlbehavior.Notes
test_server_availability()now passes via the new root redirect (GET/→ 302 →/api/v1/).knowledge/, test data, caches) are local artifacts not part of this PR.