-
-
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
a70e569
to
862d27a
Compare
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 |
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 and added the |
580101a
to
f2cb904
Compare
Oups, turns out I introduced a cyclic dependency within the test code between the new |
f2cb904
to
6374b6c
Compare
I fixed it by simplifying the |
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]>
6374b6c
to
80cb8ba
Compare
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