Merge pull request #3379 from ollama/mxyng/origins

fix: trim quotes on OLLAMA_ORIGINS
This commit is contained in:
Michael Yang 2024-03-28 14:14:18 -07:00 committed by GitHub
commit 035b274b70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1013,16 +1013,14 @@ func allowedHostsMiddleware(addr net.Addr) gin.HandlerFunc {
}
func (s *Server) GenerateRoutes() http.Handler {
var origins []string
if o := os.Getenv("OLLAMA_ORIGINS"); o != "" {
origins = strings.Split(o, ",")
}
config := cors.DefaultConfig()
config.AllowWildcard = true
config.AllowBrowserExtensions = true
config.AllowOrigins = origins
if allowedOrigins := strings.Trim(os.Getenv("OLLAMA_ORIGINS"), "\"'"); allowedOrigins != "" {
config.AllowOrigins = strings.Split(allowedOrigins, ",")
}
for _, allowOrigin := range defaultAllowOrigins {
config.AllowOrigins = append(config.AllowOrigins,
fmt.Sprintf("http://%s", allowOrigin),