Skip to content
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
4 changes: 2 additions & 2 deletions data-viewer/cypress/e2e/basic-loading/loading.cy.js
Original file line number Diff line number Diff line change
@@ -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 },
);
});
Expand All @@ -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 },
);
});
Expand Down
27 changes: 27 additions & 0 deletions plotting-service/plotting_service/plotting_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down
Loading