mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Fix RIVM-23
This commit is contained in:
parent
2003d1ca03
commit
f253448296
1 changed files with 32 additions and 23 deletions
|
@ -5,14 +5,17 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"archive/zip"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/remyoudompheng/go-misc/zipfs"
|
||||||
|
|
||||||
"github.com/RiV-chain/RiV-mesh/src/config"
|
"github.com/RiV-chain/RiV-mesh/src/config"
|
||||||
"github.com/RiV-chain/RiV-mesh/src/core"
|
"github.com/RiV-chain/RiV-mesh/src/core"
|
||||||
)
|
)
|
||||||
|
@ -232,16 +235,16 @@ func (a *AdminSocket) SetupAdminHandlers() {
|
||||||
|
|
||||||
// Start runs http server
|
// Start runs http server
|
||||||
func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
||||||
if nc.HttpAddress != "none" && nc.HttpAddress != "" && nc.WwwRoot != "none" && nc.WwwRoot != ""{
|
if nc.HttpAddress != "none" && nc.HttpAddress != "" && nc.WwwRoot != "none" && nc.WwwRoot != "" {
|
||||||
u, err := url.Parse(nc.HttpAddress)
|
u, err := url.Parse(nc.HttpAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Errorln("An error occurred parsing http address:", err)
|
a.log.Errorln("An error occurred parsing http address:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request){
|
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "Following methods are allowed: getself, getpeers. litening"+u.Host)
|
fmt.Fprintf(w, "Following methods are allowed: getself, getpeers. litening"+u.Host)
|
||||||
})
|
})
|
||||||
http.HandleFunc("/api/getself", func(w http.ResponseWriter, r *http.Request){
|
http.HandleFunc("/api/getself", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
req := &GetSelfRequest{}
|
req := &GetSelfRequest{}
|
||||||
res := &GetSelfResponse{}
|
res := &GetSelfResponse{}
|
||||||
|
@ -254,7 +257,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(b[:]))
|
fmt.Fprintf(w, string(b[:]))
|
||||||
})
|
})
|
||||||
http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request){
|
http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
req := &GetPeersRequest{}
|
req := &GetPeersRequest{}
|
||||||
res := &GetPeersResponse{}
|
res := &GetPeersResponse{}
|
||||||
|
@ -268,7 +271,13 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(b[:]))
|
fmt.Fprintf(w, string(b[:]))
|
||||||
})
|
})
|
||||||
http.Handle("/", http.FileServer(http.Dir(nc.WwwRoot)))
|
fs := http.Dir(nc.WwwRoot)
|
||||||
|
pak, err := zip.OpenReader(nc.WwwRoot)
|
||||||
|
if err == nil {
|
||||||
|
fs = zipfs.NewZipFS(&pak.Reader)
|
||||||
|
defer pak.Close()
|
||||||
|
}
|
||||||
|
http.Handle("/", http.FileServer(fs))
|
||||||
l, e := net.Listen("tcp4", u.Host)
|
l, e := net.Listen("tcp4", u.Host)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
a.log.Errorln("%s\n", e)
|
a.log.Errorln("%s\n", e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue