mirror of
https://github.com/mudler/LocalAI.git
synced 2025-02-08 12:00:13 +00:00
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>
33 lines
1.4 KiB
HTML
33 lines
1.4 KiB
HTML
<!-- Show in progress operations-->
|
|
{{ if .ProcessingModels }}
|
|
<h2
|
|
class="mt-4 mb-4 text-center text-3xl font-semibold text-gray-100">Operations in progress</h2>
|
|
{{end}}
|
|
{{$taskType:=.TaskTypes}}
|
|
|
|
{{ range $key,$value:=.ProcessingModels }}
|
|
{{ $op := index $taskType $key}}
|
|
{{$parts := split "@" $key}}
|
|
{{$modelName:=$parts._1}}
|
|
{{$repository:=$parts._0}}
|
|
{{ if not (contains "@" $key)}}
|
|
{{$repository = ""}}
|
|
{{$modelName = $key}}
|
|
{{ end }}
|
|
|
|
<div class="flex items-center justify-between bg-slate-600 p-2 mb-2 rounded-md">
|
|
<div class="flex items center">
|
|
<span class="text-gray-300"><a href="browse?term={{$parts._1}}"
|
|
class="text-white-500 inline-block bg-blue-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2 hover:bg-gray-300 hover:shadow-gray-2"
|
|
>{{$modelName}}</a> {{if $repository}} (from the '{{$repository}}' repository) {{end}}</span>
|
|
</div>
|
|
<div hx-get="browse/job/{{$value}}" hx-swap="outerHTML" hx-target="this" hx-trigger="done">
|
|
<h3 role="status" id="pblabel" >{{$op}}
|
|
<div hx-get="browse/job/progress/{{$value}}" hx-trigger="every 600ms"
|
|
hx-target="this"
|
|
hx-swap="innerHTML" ></div></h3>
|
|
</div>
|
|
</div>
|
|
{{ end }}
|
|
<!-- END Show in progress operations-->
|