From 18d5a75cdc8ed48150dd4b53a112dbc0f370e712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Silva?= Date: Wed, 27 Aug 2025 07:00:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20feat:=20Add=20support=20to=20Sub?= =?UTF-8?q?Directory=20hosting=20(#9155)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add support to SubDirectory hosting * fix: address linting and failing test * fix: browser context validation --------- Co-authored-by: Danny Avila --- api/app/clients/tools/manifest.json | 6 +- api/server/index.js | 18 +- client/index.html | 7 +- client/src/App.jsx | 2 +- client/src/components/Auth/AuthLayout.tsx | 2 +- .../Messages/Content/MarkdownComponents.tsx | 10 +- .../SidePanel/Agents/Code/ApiKeyDialog.tsx | 2 +- client/src/hooks/Endpoint/UnknownIcon.tsx | 36 ++-- client/src/hooks/SSE/useAttachmentHandler.ts | 2 +- client/src/routes/index.tsx | 190 +++++++++--------- client/vite.config.ts | 12 +- packages/data-provider/src/api-endpoints.ts | 151 ++++++++------ packages/data-provider/src/config.ts | 7 +- packages/data-provider/src/data-service.ts | 6 +- 14 files changed, 252 insertions(+), 199 deletions(-) diff --git a/api/app/clients/tools/manifest.json b/api/app/clients/tools/manifest.json index 55c1b1c51..664434f21 100644 --- a/api/app/clients/tools/manifest.json +++ b/api/app/clients/tools/manifest.json @@ -49,7 +49,7 @@ "pluginKey": "image_gen_oai", "toolkit": true, "description": "Image Generation and Editing using OpenAI's latest state-of-the-art models", - "icon": "/assets/image_gen_oai.png", + "icon": "assets/image_gen_oai.png", "authConfig": [ { "authField": "IMAGE_GEN_OAI_API_KEY", @@ -75,7 +75,7 @@ "name": "Browser", "pluginKey": "web-browser", "description": "Scrape and summarize webpage data", - "icon": "/assets/web-browser.svg", + "icon": "assets/web-browser.svg", "authConfig": [ { "authField": "OPENAI_API_KEY", @@ -170,7 +170,7 @@ "name": "OpenWeather", "pluginKey": "open_weather", "description": "Get weather forecasts and historical data from the OpenWeather API", - "icon": "/assets/openweather.png", + "icon": "assets/openweather.png", "authConfig": [ { "authField": "OPENWEATHER_API_KEY", diff --git a/api/server/index.js b/api/server/index.js index c28418b86..76fa5b7ae 100644 --- a/api/server/index.js +++ b/api/server/index.js @@ -52,7 +52,20 @@ const startServer = async () => { const appConfig = await getAppConfig(); await updateInterfacePermissions(appConfig); const indexPath = path.join(appConfig.paths.dist, 'index.html'); - const indexHTML = fs.readFileSync(indexPath, 'utf8'); + let indexHTML = fs.readFileSync(indexPath, 'utf8'); + + // In order to provide support to serving the application in a sub-directory + // We need to update the base href if the DOMAIN_CLIENT is specified and not the root path + if (process.env.DOMAIN_CLIENT) { + const clientUrl = new URL(process.env.DOMAIN_CLIENT); + const baseHref = clientUrl.pathname.endsWith('/') + ? clientUrl.pathname + : `${clientUrl.pathname}/`; + if (baseHref !== '/') { + logger.info(`Setting base href to ${baseHref}`); + indexHTML = indexHTML.replace(/base href="\/"/, `base href="${baseHref}"`); + } + } app.get('/health', (_req, res) => res.status(200).send('OK')); @@ -135,7 +148,8 @@ const startServer = async () => { const lang = req.cookies.lang || req.headers['accept-language']?.split(',')[0] || 'en-US'; const saneLang = lang.replace(/"/g, '"'); - const updatedIndexHtml = indexHTML.replace(/lang="en-US"/g, `lang="${saneLang}"`); + let updatedIndexHtml = indexHTML.replace(/lang="en-US"/g, `lang="${saneLang}"`); + res.type('html'); res.send(updatedIndexHtml); }); diff --git a/client/index.html b/client/index.html index c05fbea5a..c94c3981b 100644 --- a/client/index.html +++ b/client/index.html @@ -2,15 +2,16 @@ + LibreChat - - - + + +