Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

feat: webui dashboard #34

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
repository: filecoin-project/saturn-webui
# Update tag to deploy new web UI.
tag: v0.0.11
tag: v0.0.14
fileName: saturn-webui.tar.gz
out-file-path: resources/webui
-
Expand Down
18 changes: 14 additions & 4 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ func main() {
fmt.Fprintf(os.Stderr, "Invalid FIL_WALLET_ADDRESS format: %s\n", err.Error())
os.Exit(3)
}
conf, err := json.Marshal(config{FilAddr: filAddr})
cfg := config{FilAddr: filAddr}
cfgJson, err := json.Marshal(cfg)
if err != nil {
panic(errors.New("failed to serialize config"))
}

m := mux.NewRouter()
m.PathPrefix("/config").Handler(http.HandlerFunc(configHandler(conf)))
m.PathPrefix("/webui").Handler(http.HandlerFunc(webuiHandler))
m.PathPrefix("/config").Handler(http.HandlerFunc(configHandler(cfgJson)))
m.PathPrefix("/webui").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
webuiHandler(cfg, w, r)
}))

srv := &http.Server{
Handler: m,
Expand All @@ -76,10 +79,17 @@ func main() {
}
}

func webuiHandler(w http.ResponseWriter, r *http.Request) {
func webuiHandler(cfg config, w http.ResponseWriter, r *http.Request) {
rootDir := "webui"
path := strings.TrimPrefix(r.URL.Path, "/")

if path == rootDir {
targetUrl := fmt.Sprintf("/%s/address/%s", rootDir, cfg.FilAddr)
statusCode := 303 // See Other (a temporary redirect)
http.Redirect(w, r, targetUrl, statusCode)
return
}

_, err := resources.WebUI.Open(path)
if path == rootDir || os.IsNotExist(err) {
// file does not exist, serve index.html
Expand Down