37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ui.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
package ui
import (
"crypto/tls"
"io"
"net/http"
"os"
"path/filepath"
"github.com/rancher/norman/parse"
"github.com/rancher/rancher/pkg/settings"
"github.com/sirupsen/logrus"
)
var (
insecureClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
)
func Content() http.Handler {
return http.FileServer(http.Dir(settings.UIPath.Get()))
}
func UI(next http.Handler) http.Handler {
_, err := os.Stat(indexHTML())
local := err == nil
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if parse.IsBrowser(req, true) {
if local && settings.UIIndex.Get() == "local" {
http.ServeFile(resp, req, indexHTML())
} else {
ui(resp, req)
}
} else {
next.ServeHTTP(resp, req)
}
})
}
func indexHTML() string {
return filepath.Join(settings.UIPath.Get(), "index.html")
}
func ui(resp http.ResponseWriter, req *http.Request) {
if err := serveIndex(resp, req); err != nil {
logrus.Errorf("failed to serve UI: %v", err)
resp.WriteHeader(500)
}
}
func serveIndex(resp http.ResponseWriter, req *http.Request) error {
r, err := insecureClient.Get(settings.UIIndex.Get())
if err != nil {
return err
}
defer r.Body.Close()
_, err = io.Copy(resp, r.Body)
return err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.9

搜索帮助