LocalAI/core/http/static/assets
Max Goltzsche 8cc2d01caa
feat(ui): path prefix support via HTTP header (#4497)
Makes the web app honour the `X-Forwarded-Prefix` HTTP request header that may be sent by a reverse-proxy in order to inform the app that its public routes contain a path prefix.
For instance this allows to serve the webapp via a reverse-proxy/ingress controller under a path prefix/sub path such as e.g. `/localai/` while still being able to use the regular LocalAI routes/paths without prefix when directly connecting to the LocalAI server.

Changes:
* Add new `StripPathPrefix` middleware to strip the path prefix (provided with the `X-Forwarded-Prefix` HTTP request header) from the request path prior to matching the HTTP route.
* Add a `BaseURL` utility function to build the base URL, honouring the `X-Forwarded-Prefix` HTTP request header.
* Generate the derived base URL into the HTML (`head.html` template) as `<base/>` tag.
* Make all webapp-internal URLs (within HTML+JS) relative in order to make the browser resolve them against the `<base/>` URL specified within each HTML page's header.
* Make font URLs within the CSS files relative to the CSS file.
* Generate redirect location URLs using the new `BaseURL` function.
* Use the new `BaseURL` function to generate absolute URLs within gallery JSON responses.

Closes #3095

TL;DR:
The header-based approach allows to move the path prefix configuration concern completely to the reverse-proxy/ingress as opposed to having to align the path prefix configuration between LocalAI, the reverse-proxy and potentially other internal LocalAI clients.
The gofiber swagger handler already supports path prefixes this way, see e2d9e9916d/swagger.go (L79)

Signed-off-by: Max Goltzsche <max.goltzsche@gmail.com>
2025-01-07 17:18:21 +01:00
..
fontawesome feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
alpine.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
flowbite.min.js feat(ui): move model detailed info to a modal (#4086) 2024-11-06 18:25:59 +01:00
font1.css feat(ui): path prefix support via HTTP header (#4497) 2025-01-07 17:18:21 +01:00
font2.css feat(ui): path prefix support via HTTP header (#4497) 2025-01-07 17:18:21 +01:00
fontawesome.css feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
highlightjs.css feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
highlightjs.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
htmx.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOlCnqEu92Fr1MmEU9fBBc9.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOlCnqEu92Fr1MmEU9vAw.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOlCnqEu92Fr1MmSU5fBBc9.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOlCnqEu92Fr1MmWUlfBBc9.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOlCnqEu92Fr1MmYUtfBBc9.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOmCnqEu92Fr1Me5Q.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
KFOmCnqEu92Fr1Mu4mxP.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
marked.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
purify.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
tailwindcss.js feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
tw-elements.css feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
tw-elements.js feat(p2p): Federation and AI swarms (#2723) 2024-07-08 22:04:06 +02:00
UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYMZg.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuGKYMZg.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00
UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfMZg.ttf feat(webui): statically embed js/css assets (#2348) 2024-05-19 18:24:27 +02:00