diff --git a/data-viewer/cypress/e2e/basic-loading/loading.cy.js b/data-viewer/cypress/e2e/basic-loading/loading.cy.js index f7c2a6c5..ef35d7ec 100644 --- a/data-viewer/cypress/e2e/basic-loading/loading.cy.js +++ b/data-viewer/cypress/e2e/basic-loading/loading.cy.js @@ -1,7 +1,7 @@ describe("Basic loading tests for test nexus file", () => { beforeEach(() => { cy.visit( - "http://localhost:3000/view/mari/20024/MAR29531_10.5meV_sa.nxspe", + "http://localhost:3000/view/MARI/20024/MAR29531_10.5meV_sa.nxspe", { failOnStatusCode: false }, ); }); @@ -18,7 +18,7 @@ describe("Test for loading nexus file with space in name", () => { beforeEach(() => { // This URL DOES have a whitespace, but the underline in most IDEs makes it look like an underscore cy.visit( - "http://localhost:3000/view/mari/20024/MAR29531 10.5meV_sa.nxspe", + "http://localhost:3000/view/MARI/20024/MAR29531 10.5meV_sa.nxspe", { failOnStatusCode: false }, ); }); diff --git a/plotting-service/plotting_service/plotting_api.py b/plotting-service/plotting_service/plotting_api.py index 555136a0..824e82d5 100644 --- a/plotting-service/plotting_service/plotting_api.py +++ b/plotting-service/plotting_service/plotting_api.py @@ -8,6 +8,7 @@ from pathlib import Path from fastapi import FastAPI, HTTPException +from fastapi.openapi.models import Response from h5grove.fastapi_utils import router, settings # type: ignore from starlette.middleware.cors import CORSMiddleware from starlette.requests import Request @@ -32,6 +33,17 @@ logger = logging.getLogger(__name__) logger.info("Starting Plotting Service") + +class EndpointFilter(logging.Filter): + """Filter out log messages containing /healthz or /ready.""" + + def filter(self, record: logging.LogRecord) -> bool: + """Filter out log messages containing /healthz or /ready.""" + return record.getMessage().find("/healthz") == -1 and record.getMessage().find("/ready") == -1 + + +logging.getLogger("uvicorn.access").addFilter(EndpointFilter()) + DEV_MODE = os.environ.get("DEV_MODE", "False").lower() == "true" if DEV_MODE: logger.info("Development only mode") @@ -54,6 +66,21 @@ settings.base_dir = Path(CEPH_DIR).resolve() +@app.middleware("http") +async def remove_trailing_slash(request: Request, call_next: typing.Callable[..., typing.Any]) -> Response: + path = request.scope.get("path", "") + # If the path ends with a slash (and isn't just the root "/"), strip it + if path != "/" and path.endswith("/"): + new_path = path.rstrip("/") + + request.scope["path"] = new_path + + if "raw_path" in request.scope: + request.scope["raw_path"] = new_path.encode("utf-8") + + return await call_next(request) + + @app.middleware("http") async def check_permissions(request: Request, call_next: typing.Callable[..., typing.Any]) -> typing.Any: # noqa: C901, PLR0911 """Middleware that checks the requestee token has permissions for that