37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ui.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-02-21 14:39 . Support WrapTransport in RKE
package ui
import (
"io"
"net/http"
"os"
"path/filepath"
"strings"
"crypto/tls"
"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 {
local := false
_, err := os.Stat(indexHTML())
if err == nil {
local = true
}
if local && !strings.HasPrefix(settings.ServerVersion.Get(), "v") {
local = false
}
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if parse.IsBrowser(req, true) {
if 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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.7-rc7

搜索帮助

0d507c66 1850385 C8b1a773 1850385