Skip to content

Commit

Permalink
embed admin ui files
Browse files Browse the repository at this point in the history
  • Loading branch information
taoso committed May 23, 2021
1 parent b9a7a9f commit ee08a28
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
anylink
conf/data.db
3 changes: 1 addition & 2 deletions admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import (

// 开启服务
func StartAdmin() {

r := mux.NewRouter()
r.Use(authMiddleware)

r.Handle("/", http.RedirectHandler("/ui/", http.StatusFound)).Name("index")
r.PathPrefix("/ui/").Handler(
http.StripPrefix("/ui/", http.FileServer(http.Dir(base.Cfg.UiPath))),
http.StripPrefix("/ui/", http.FileServer(getUiFS())),
).Name("static")
r.HandleFunc("/base/login", Login).Name("login")

Expand Down
16 changes: 16 additions & 0 deletions admin/uifs_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build !prod

package admin

import (
"fmt"
"net/http"
"os"

"github.com/go-kiss/anylink/base"
)

func getUiFS() http.FileSystem {
fmt.Println(base.Cfg.UiPath)
return http.FS(os.DirFS(base.Cfg.UiPath))
}
21 changes: 21 additions & 0 deletions admin/uifs_prod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build prod

package admin

import (
"embed"
"io/fs"
"net/http"
)

//go:embed web/ui
var embededFiles embed.FS

func getUiFS() http.FileSystem {
fsys, err := fs.Sub(embededFiles, "web/ui")
if err != nil {
panic(err)
}

return http.FS(fsys)
}
2 changes: 1 addition & 1 deletion conf/server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ db_file = "./data.db"
#证书文件
cert_file = "./test_vpn_cert.pem"
cert_key = "./test_vpn_key.pem"
ui_path = "../ui"
ui_path = "../admin/web/ui"
files_path = "../files"
#日志目录,为空写入标准输出
#log_path = "../log"
Expand Down

0 comments on commit ee08a28

Please sign in to comment.