This commit is contained in:
matst80
2024-11-15 09:28:58 +01:00
parent 7795fc9c39
commit 00d65035d0
3 changed files with 9 additions and 32 deletions

View File

@@ -57,6 +57,7 @@ func ErrorHandler(fn func(w http.ResponseWriter, r *http.Request) error) func(w
func (s *PoolServer) WriteResult(w http.ResponseWriter, result *FrameWithPayload) error {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("X-Pod-Name", s.pod_name)
if result.StatusCode != 200 {
log.Printf("Call error: %d\n", result.StatusCode)
@@ -117,6 +118,12 @@ func (s *PoolServer) HandleSetDelivery(w http.ResponseWriter, r *http.Request) e
func (s *PoolServer) Serve() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("OPTIONS /{id}", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.WriteHeader(http.StatusOK)
})
mux.HandleFunc("GET /{id}", ErrorHandler(s.HandleGet))
mux.HandleFunc("GET /{id}/add/{sku}", ErrorHandler(s.HandleAddSku))
mux.HandleFunc("DELETE /{id}/{itemId}", ErrorHandler(s.HandleDeleteItem))