Skip to content

Conversation

@jpsfs
Copy link
Contributor

@jpsfs jpsfs commented Aug 19, 2025

🌐 feat: Add support to SubDirectory hosting

Summary

The changes in this Pull Request implement the Enhancement Request described in #1701.
With this changes LibreChat can now be hosted in a subdirectory or path.

I've implemented this change reusing the DOMAIN_CLIENT and DOMAIN_SERVER environment variables, which I assume was the original idea of the author. Thus I've not made any documentation change. If DOMAIN_CLIENT is set with a URL that includes a path, then the system will adapt itself to it.

Change Type

Please delete any irrelevant options.

  • New feature (non-breaking change which adds functionality)

Testing

I've setup a reverse proxy in front of the LibreChat image, redirecting the traffic of "/mycustomaddress" to port 3080. The setup was made using the strip-prefix middleware, to ensure the requests reach port 3080 already without the "/mycustomaddress" part of the URL.

Test Configuration:

LibreChat relevant env vars:

DOMAIN_CLIENT=http://{{yourpublicdomain:port}}/mycustomdomain
DOMAIN_SERVER=http://{{yourpublicdomain:port}}/mycustomdomain

Traefik configuration file:

http:
  routers:
    my-host-app:
      rule: "PathPrefix(`/mycustomdomain`)"
      entryPoints:
        - web
      service: librechat
      middlewares:
        - strip-path

  services:
    librechat:
      loadBalancer:
        servers:
          - url: "http://host.docker.internal:3080"

  middlewares:
    strip-path:
      stripPrefix:
        prefixes:
          - "/mycustomdomain"

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes

@dacosta444
Copy link

Great work! This is a must to have LibreChat behind a reverse proxy!

@jpsfs
Copy link
Contributor Author

jpsfs commented Aug 20, 2025

@danny-avila updated, test fixed and linting issues reviewed 🙏🏼

@digas111
Copy link

I tested this on my side and it solves my use case:
#8919

@jpsfs
Copy link
Contributor Author

jpsfs commented Aug 25, 2025

@danny-avila Merge conflict resolved.

@jpsfs
Copy link
Contributor Author

jpsfs commented Aug 26, 2025

Hi @danny-avila, is there anything I can do to help streamline the process?

@danny-avila danny-avila changed the base branch from main to dev August 27, 2025 05:52
@danny-avila danny-avila merged commit 18d5a75 into danny-avila:dev Aug 27, 2025
7 checks passed
@jpsfs jpsfs deleted the dev/supportSubDirectory branch August 27, 2025 09:37
@danny-avila
Copy link
Owner

@jpsfs I missed this, it looks this PR created the issue highlighted here: #9300

No worries, though, this is why we have the dev branch now to help catch issues.

@danny-avila
Copy link
Owner

This fixes it:

danny:~/LibreChat$ git diff dev -- packages/data-provider/src/api-endpoints.ts
diff --git a/packages/data-provider/src/api-endpoints.ts b/packages/data-provider/src/api-endpoints.ts
index 59ede0905..8b6be0f5a 100644
--- a/packages/data-provider/src/api-endpoints.ts
+++ b/packages/data-provider/src/api-endpoints.ts
@@ -58,7 +58,7 @@ export const messages = (params: q.MessagesListParams) => {
     return `${messagesRoot}/${conversationId}`;
   }
 
-  return `${messagesRoot}{buildQuery(rest)}`;
+  return `${messagesRoot}${buildQuery(rest)}`;
 };
 
 export const messagesArtifacts = (messageId: string) => `${messagesRoot}/artifacts/${messageId}`;

danny-avila added a commit that referenced this pull request Aug 27, 2025
* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
@jpsfs
Copy link
Contributor Author

jpsfs commented Aug 27, 2025

Damn... Thank you for the quick fix!

lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 28, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Aug 29, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Sep 4, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
lihe8811 pushed a commit to lihe8811/LibreChat that referenced this pull request Sep 4, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
pedrojreis pushed a commit to nosportugal/LibreChat that referenced this pull request Sep 4, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
pedrojreis pushed a commit to nosportugal/LibreChat that referenced this pull request Sep 4, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
arbreton pushed a commit to arbreton/LibreChat that referenced this pull request Oct 9, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
arbreton pushed a commit to arbreton/LibreChat that referenced this pull request Oct 9, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
Guiraud pushed a commit to Guiraud/LibreChat that referenced this pull request Nov 21, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
Guiraud pushed a commit to Guiraud/LibreChat that referenced this pull request Nov 21, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
patricksn3ll pushed a commit to patricksn3ll/LibreChat that referenced this pull request Dec 11, 2025
* feat: Add support to SubDirectory hosting

* fix: address linting and failing test

* fix: browser context validation

---------

Co-authored-by: Danny Avila <[email protected]>
patricksn3ll pushed a commit to patricksn3ll/LibreChat that referenced this pull request Dec 11, 2025
danny-avila#9312)

* feat: move buildTree function for message hierarchy to data provider

* refactor: consolidate buildTree import from utils to data provider

* fix: correct string interpolation in messages function, which caused message search requests to fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants