mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	
							parent
							
								
									1c9fd32533
								
							
						
					
					
						commit
						12c3103039
					
				
					 1 changed files with 23 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -5,17 +5,14 @@ import (
 | 
			
		|||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sort"
 | 
			
		||||
 | 
			
		||||
	"archive/zip"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/remyoudompheng/go-misc/zipfs"
 | 
			
		||||
 | 
			
		||||
	"github.com/RiV-chain/RiV-mesh/src/config"
 | 
			
		||||
	"github.com/RiV-chain/RiV-mesh/src/core"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -235,16 +232,16 @@ func (a *AdminSocket) SetupAdminHandlers() {
 | 
			
		|||
 | 
			
		||||
// Start runs http server
 | 
			
		||||
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)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			a.log.Errorln("An error occurred parsing http address:", err)
 | 
			
		||||
			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)
 | 
			
		||||
		})
 | 
			
		||||
		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")
 | 
			
		||||
			req := &GetSelfRequest{}
 | 
			
		||||
			res := &GetSelfResponse{}
 | 
			
		||||
| 
						 | 
				
			
			@ -257,7 +254,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
 | 
			
		|||
			}
 | 
			
		||||
			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")
 | 
			
		||||
			req := &GetPeersRequest{}
 | 
			
		||||
			res := &GetPeersResponse{}
 | 
			
		||||
| 
						 | 
				
			
			@ -271,13 +268,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
 | 
			
		|||
			}
 | 
			
		||||
			fmt.Fprintf(w, string(b[:]))
 | 
			
		||||
		})
 | 
			
		||||
		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))
 | 
			
		||||
		http.Handle("/", http.FileServer(http.Dir(nc.WwwRoot)))
 | 
			
		||||
		l, e := net.Listen("tcp4", u.Host)
 | 
			
		||||
		if e != nil {
 | 
			
		||||
			a.log.Errorln("%s\n", e)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue