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

Commit

Permalink
Merge pull request #34 from filecoin-project/feat/webui-dashboard
Browse files Browse the repository at this point in the history
feat: webui dashboard
  • Loading branch information
bajtos authored Jul 13, 2022
2 parents 370088e + 54e2994 commit 44ae67e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit 44ae67e

Please sign in to comment.