mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
assets: use statik to compile static files into binary files
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/fatedier/frp/src/assets"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -33,8 +35,9 @@ func RunDashboardServer(addr string, port int64) (err error) {
|
||||
mux.HandleFunc("/api/reload", apiReload)
|
||||
mux.HandleFunc("/api/proxies", apiProxies)
|
||||
|
||||
// view see dashboard_view.go
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./assets"))))
|
||||
// view, see dashboard_view.go
|
||||
mux.Handle("/favicon.ico", http.FileServer(assets.FileSystem))
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))
|
||||
mux.HandleFunc("/", viewDashboard)
|
||||
|
||||
address := fmt.Sprintf("%s:%d", addr, port)
|
||||
|
||||
@@ -17,17 +17,22 @@ package server
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/fatedier/frp/src/assets"
|
||||
"github.com/fatedier/frp/src/models/metric"
|
||||
"github.com/fatedier/frp/src/utils/log"
|
||||
)
|
||||
|
||||
func viewDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
metrics := metric.GetAllProxyMetrics()
|
||||
t := template.Must(template.New("index.html").Delims("<<<", ">>>").ParseFiles(path.Join(AssetsDir, "index.html")))
|
||||
dashboardTpl, err := assets.ReadFile("index.html")
|
||||
if err != nil {
|
||||
http.Error(w, "get dashboard template file error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
t := template.Must(template.New("index.html").Delims("<<<", ">>>").Parse(dashboardTpl))
|
||||
|
||||
err := t.Execute(w, metrics)
|
||||
err = t.Execute(w, metrics)
|
||||
if err != nil {
|
||||
log.Warn("parse template file [index.html] error: %v", err)
|
||||
http.Error(w, "parse template file error", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user