Feature: add custom ui support in API
This commit is contained in:
@ -17,6 +17,8 @@ import (
|
||||
var (
|
||||
serverSecret = ""
|
||||
serverAddr = ""
|
||||
|
||||
uiPath = ""
|
||||
)
|
||||
|
||||
type Traffic struct {
|
||||
@ -24,6 +26,10 @@ type Traffic struct {
|
||||
Down int64 `json:"down"`
|
||||
}
|
||||
|
||||
func SetUIPath(path string) {
|
||||
uiPath = path
|
||||
}
|
||||
|
||||
func Start(addr string, secret string) {
|
||||
if serverAddr != "" {
|
||||
return
|
||||
@ -49,6 +55,14 @@ func Start(addr string, secret string) {
|
||||
r.Mount("/proxies", proxyRouter())
|
||||
r.Mount("/rules", ruleRouter())
|
||||
|
||||
if uiPath != "" {
|
||||
fs := http.StripPrefix("/ui", http.FileServer(http.Dir(uiPath)))
|
||||
r.Get("/ui", http.RedirectHandler("/ui/", 301).ServeHTTP)
|
||||
r.Get("/ui/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
fs.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
log.Infoln("RESTful API listening at: %s", addr)
|
||||
err := http.ListenAndServe(addr, r)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user