diff --git a/cmd/honey-tracker/main.go b/cmd/honey-tracker/main.go
index 8926fbb..45325e2 100644
--- a/cmd/honey-tracker/main.go
+++ b/cmd/honey-tracker/main.go
@@ -3,14 +3,12 @@ package main
import (
"context"
"fmt"
- "html/template"
- "log"
- "net/http"
"os"
"os/exec"
"time"
- "github.com/golang-jwt/jwt/v5"
+ "github.com/streamingfast/honey-tracker/web"
+
"github.com/spf13/cobra"
"github.com/streamingfast/bstream"
"github.com/streamingfast/cli/sflags"
@@ -135,7 +133,7 @@ func rootRun(cmd *cobra.Command, args []string) error {
}()
go func() {
- serveHttp()
+ web.ServeHttp()
}()
err = sinker.Run(ctx)
@@ -193,86 +191,6 @@ func trackPrice(db *data.Psql, logger *zap.Logger) error {
}
}
-const METABASE_SITE_URL = "http://34.170.245.114:3000"
-
-var METABASE_SECRET_KEY = os.Getenv("SECRET_KEY")
-
-type CustomClaims struct {
- Resource map[string]int `json:"resource"`
- Params map[string]interface{} `json:"params"`
- jwt.RegisteredClaims
-}
-
-type PageData struct {
- IFrameUrl string
-}
-
-func handler(w http.ResponseWriter, r *http.Request) {
-
- claims := CustomClaims{
- Resource: map[string]int{"dashboard": 1},
- Params: map[string]interface{}{},
- RegisteredClaims: jwt.RegisteredClaims{
- ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 10)),
- },
- }
-
- // Create a new token object
- token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
- secretKey := []byte(METABASE_SECRET_KEY)
-
- tokenString, err := token.SignedString(secretKey)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- fmt.Printf("error: %v\n", err)
- return
- }
-
- tmpl, err := template.New("webpage").Parse(tmpl)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- fmt.Printf("error: %v\n", err)
- return
- }
-
- iframeUrl := METABASE_SITE_URL + "/embed/dashboard/" + tokenString + "#bordered=true&titled=true"
-
- tmplData := PageData{
- IFrameUrl: iframeUrl,
- }
-
- err = tmpl.Execute(w, tmplData)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- fmt.Printf("error: %v\n", err)
- return
- }
-}
-
-const tmpl = `
-
-
-
-
- Hivemaper Dashboard
-
-
-
-
-`
-
-func serveHttp() {
- http.HandleFunc("/", handler)
- log.Println("Starting server on :8080")
- log.Fatal(http.ListenAndServe(":8080", nil))
-}
-
func checkError(err error) {
if err != nil {
panic(err)
diff --git a/cmd/www/main.go b/cmd/www/main.go
new file mode 100644
index 0000000..3067d44
--- /dev/null
+++ b/cmd/www/main.go
@@ -0,0 +1,7 @@
+package main
+
+import "github.com/streamingfast/honey-tracker/web"
+
+func main() {
+ web.ServeHttp()
+}
diff --git a/web/index.html b/web/index.html
deleted file mode 100644
index 40afa0d..0000000
--- a/web/index.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/web/server.go b/web/server.go
new file mode 100644
index 0000000..d69c83a
--- /dev/null
+++ b/web/server.go
@@ -0,0 +1,115 @@
+package web
+
+import (
+ "fmt"
+ "html/template"
+ "log"
+ "net/http"
+ "os"
+
+ "github.com/golang-jwt/jwt/v5"
+)
+
+const METABASE_SITE_URL = "http://34.170.245.114:3000"
+
+var METABASE_SECRET_KEY = os.Getenv("SECRET_KEY")
+
+type CustomClaims struct {
+ Resource map[string]int `json:"resource"`
+ Params map[string]interface{} `json:"params"`
+ jwt.RegisteredClaims
+}
+
+type PageData struct {
+ IFrameUrl string
+}
+
+func handler(w http.ResponseWriter, r *http.Request) {
+
+ //claims := CustomClaims{
+ // Resource: map[string]int{"dashboard": 1},
+ // Params: map[string]interface{}{},
+ // RegisteredClaims: jwt.RegisteredClaims{
+ // ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 10)),
+ // },
+ //}
+ //
+ //if METABASE_SECRET_KEY == "" {
+ // panic("METABASE_SECRET_KEY not set")
+ //}
+ //fmt.Println("METABASE_SECRET_KEY: " + METABASE_SECRET_KEY)
+ //// Create a new token object
+ //token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
+ //secretKey := []byte(METABASE_SECRET_KEY)
+ //
+ //tokenString, err := token.SignedString(secretKey)
+ //if err != nil {
+ // http.Error(w, err.Error(), http.StatusInternalServerError)
+ // fmt.Printf("error: %v\n", err)
+ // return
+ //}
+
+ tmpl, err := template.New("webpage").Parse(tmpl)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ fmt.Printf("error: %v\n", err)
+ return
+ }
+
+ //iframeUrl := METABASE_SITE_URL + "/embed/dashboard/" + tokenString + "#bordered=true&titled=true"
+ //
+ tmplData := PageData{
+ //IFrameUrl: iframeUrl,
+ }
+
+ err = tmpl.Execute(w, tmplData)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ fmt.Printf("error: %v\n", err)
+ return
+ }
+}
+
+const tmpl = `
+
+
+
+
+ Hivemaper Dashboard
+
+
+
+
+
+`
+
+//const tmpl = `
+//
+//
+//
+//
+// Hivemaper Dashboard
+//
+//
+//
+//
+//`
+
+func ServeHttp() {
+ http.HandleFunc("/", handler)
+ log.Println("Starting server on :8080")
+ log.Fatal(http.ListenAndServe(":8080", nil))
+}