app/ui: use envconfig.Host() for ollama proxy to handle unspecified bind addresses
This commit is contained in:
parent
8ed1adf3db
commit
9b462f89ca
19
app/ui/ui.go
19
app/ui/ui.go
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
@ -118,23 +117,7 @@ func (s *Server) log() *slog.Logger {
|
||||||
|
|
||||||
// ollamaProxy creates a reverse proxy handler to the Ollama server
|
// ollamaProxy creates a reverse proxy handler to the Ollama server
|
||||||
func (s *Server) ollamaProxy() http.Handler {
|
func (s *Server) ollamaProxy() http.Handler {
|
||||||
ollamaHost := os.Getenv("OLLAMA_HOST")
|
target := envconfig.Host()
|
||||||
if ollamaHost == "" {
|
|
||||||
ollamaHost = "http://127.0.0.1:11434"
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(ollamaHost, "http://") && !strings.HasPrefix(ollamaHost, "https://") {
|
|
||||||
ollamaHost = "http://" + ollamaHost
|
|
||||||
}
|
|
||||||
|
|
||||||
target, err := url.Parse(ollamaHost)
|
|
||||||
if err != nil {
|
|
||||||
s.log().Error("failed to parse OLLAMA_HOST", "error", err, "host", ollamaHost)
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "failed to configure proxy", http.StatusInternalServerError)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
s.log().Info("configuring ollama proxy", "target", target.String())
|
s.log().Info("configuring ollama proxy", "target", target.String())
|
||||||
|
|
||||||
proxy := httputil.NewSingleHostReverseProxy(target)
|
proxy := httputil.NewSingleHostReverseProxy(target)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue