fix: add basePath pattern to support login/register and image paths #10116
  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.
  
    
  
    
Summary
This PR is meant to address #10013 which is a bug in the new feature, #9155
I've included unit tests, and run the test suites in this project. A simplified test case is included below.
This is currently relying on
DOMAIN_CLIENT, wasn't sure if it you would like to add a dedicated environment variable, or how you'd like to approach this fix in general, but I gave it my best shot.Server-side path injection - Created
getBasePath()utility that readsDOMAIN_CLIENTenv var and prepends subdirectory paths (e.g.,/librechat) to all image URLs in AI-generated responses, tool outputs (StableDiffusion), and code interpreter resultsClient-side path resolution - Updated React components (
Image.tsx, markdown renderers) to prepend the base URL from the HTML<base>tag to image paths, fixing broken images when the app is served from a subdirectory likehttps://example.com/librechat/Security & routing updates - Fixed image validation middleware to correctly validate paths with base prefixes, updated auth redirects to use base-aware URLs (
loginPage(),registerPage()), and added comprehensive test coverage (150+ new tests) for subdirectory deployment scenariosChange Type
Testing
With the following files in the project root:
README.md, as well as having OpenAI image generation configureddocker compose up --buildTest Configuration:
docker-compose.override.ymlnginx-test.confChecklist