element/server/update.go
Evan Hazlett a89aa40dda
proxy: start on api and caddy based proxy
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2017-07-29 22:54:43 -04:00

24 lines
564 B
Go

package server
import (
"encoding/json"
"fmt"
"net/http"
"github.com/ehazlett/element/proxy"
)
func (s *Server) updateFrontend(w http.ResponseWriter, r *http.Request) {
var frontend *proxy.Frontend
if err := json.NewDecoder(r.Body).Decode(&frontend); err != nil {
http.Error(w, fmt.Sprintf("invalid fronend: %s", err), http.StatusBadRequest)
return
}
if err := s.proxy.UpdateFrontend(frontend); err != nil {
http.Error(w, fmt.Sprintf("error adding frontend: %s", err), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}