diff --git a/pages/faucet.html b/pages/faucet.html new file mode 100644 index 0000000..337d33c --- /dev/null +++ b/pages/faucet.html @@ -0,0 +1,76 @@ + + + + + + + + Faucet + + + + + +
+

Faucet

+

Network: {{ .Network }}

+ +
+
+ + +
+
+ + +
+ +
+
+
+ + + + + diff --git a/router/faucet_handler.go b/router/faucet_handler.go index 33168e4..0d0c96f 100644 --- a/router/faucet_handler.go +++ b/router/faucet_handler.go @@ -2,6 +2,7 @@ package router import ( "encoding/json" + "html/template" "io" "net/http" ) @@ -123,3 +124,34 @@ func parseRequestBody(body io.ReadCloser) map[string]interface{} { return decodedBody } + +// HandleFaucetPage will return an HTML page that will allow us to interact with the faucet endpoints +func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { + filepath := "pages/faucet.html" + + tmpl, err := template.ParseFiles(filepath) + if err != nil { + http.Error(res, "Page not found", http.StatusNotFound) + return + } + + type PageData struct { + Network string + Asset string + } + network := r.Config.Chain() + asset := "BTC" + if network == "liquid" { + asset = "L-BTC" + } + + data := PageData{ + Network: network, + Asset: asset, + } + + err = tmpl.Execute(res, data) + if err != nil { + http.Error(res, "Failed to render page", http.StatusInternalServerError) + } +} diff --git a/router/main.go b/router/main.go index af96355..7f4f4a5 100644 --- a/router/main.go +++ b/router/main.go @@ -52,6 +52,7 @@ func NewRouter(config cfg.Config) *Router { faucet := faucet.NewFaucet(config.RPCServerURL(), rpcClient) r.Faucet = faucet r.HandleFunc("/faucet", r.HandleFaucetRequest).Methods(http.MethodPost, http.MethodOptions) + r.HandleFunc("/faucet", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) if config.Chain() == "liquid" { registry, _ := helpers.NewRegistry(config.RegistryPath()) r.Registry = registry