-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui): path prefix support via HTTP header #4497
Open
mgoltzsche
wants to merge
1
commit into
mudler:master
Choose a base branch
from
mgoltzsche:add-path-prefix-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+470
−105
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
mgoltzsche
force-pushed
the
add-path-prefix-support
branch
from
December 25, 2024 21:46
a70e569
to
862d27a
Compare
mgoltzsche
changed the title
feat(ui): make web app support path prefix via header
feat(ui): path prefix support via HTTP header
Dec 25, 2024
mgoltzsche
force-pushed
the
add-path-prefix-support
branch
3 times, most recently
from
December 26, 2024 00:39
8cdff73
to
9efa59e
Compare
Thank you 💯 - it makes totally sense as an addition to me. As soon as I have a bit of time will try to test out locally too to see if there aren't any regression |
mgoltzsche
force-pushed
the
add-path-prefix-support
branch
from
December 26, 2024 16:58
9efa59e
to
580101a
Compare
The app test failed. I think I fixed it now. Please re-run the workflow. UPDATE: Also, I rebased the PR. |
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 mudler#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 https://github.com/gofiber/swagger/blob/e2d9e9916d8809e8b23c4365f8acfbbd8a71c4cd/swagger.go#L79 Signed-off-by: Max Goltzsche <[email protected]>
mgoltzsche
force-pushed
the
add-path-prefix-support
branch
from
December 26, 2024 18:00
580101a
to
f2cb904
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
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. 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:
StripPathPrefix
middleware to strip the path prefix (provided with theX-Forwarded-Prefix
HTTP request header) from the request path prior to matching the HTTP route.BaseURL
utility function to build the base URL, honouring theX-Forwarded-Prefix
HTTP request header.BaseURL
function into the HTML (head.html
andlogin.html
templates) as<base/>
tag.<base/>
URL specified within each HTML page's header.BaseURL
function.BaseURL
function to generate absolute URLs within gallery JSON responses.This PR fixes #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 here.
Known limitations:
Notes for Reviewers
Apart from the added automated tests, I did some manual testing and grepping, hoping to have all URLs covered.
Signed commits