diff --git a/webapi/API.go b/webapi/API.go index 76bf27c..9dbff8a 100644 --- a/webapi/API.go +++ b/webapi/API.go @@ -21,8 +21,15 @@ import ( // Router can be used to register additional API functions var Router *mux.Router -// WSUpgrader can be used to provide web sockets. It uses all default options and allows all requests. -var WSUpgrader = websocket.Upgrader{} +// WSUpgrader is used for websocket functionality. It allows all requests. +var WSUpgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, + CheckOrigin: func(r *http.Request) bool { + // allow all connections by default + return true + }, +} // Start starts the API. ListenAddresses is a list of IP:Ports func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKey string, TimeoutRead, TimeoutWrite time.Duration) { @@ -30,10 +37,6 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe return } - WSUpgrader.CheckOrigin = func(r *http.Request) bool { - return true - } - Router = mux.NewRouter() Router.HandleFunc("/test", apiTest).Methods("GET") @@ -107,8 +110,3 @@ func DecodeJSON(w http.ResponseWriter, r *http.Request, data interface{}) (err e return nil } - -func apiTest(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - w.Write([]byte("ok")) -} diff --git a/webapi/Status.go b/webapi/Status.go index 26a9729..6bba17d 100644 --- a/webapi/Status.go +++ b/webapi/Status.go @@ -13,6 +13,11 @@ import ( "github.com/PeernetOfficial/core" ) +func apiTest(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) +} + type apiResponseStatus struct { Status int `json:"status"` // Status code: 0 = Ok. IsConnected bool `json:"isconnected"` // Whether connected to Peernet.