1 Commits
v0.2 ... v0.3

Author SHA1 Message Date
b11c8cbcbf fix: execute script in background to not block response 2024-05-06 17:28:48 +02:00

18
main.go
View File

@@ -40,7 +40,6 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w
defer r.Body.Close()
authHeader := r.Header.Get("Authorization")
log.Println("authHeader", authHeader)
if authHeader != secret {
http.Error(w, "Signatures didn't match", http.StatusUnauthorized)
return
@@ -57,22 +56,17 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w
http.Error(w, "not found", http.StatusNotFound)
return
}
log.Println("body", body)
// Parse the JSON payload
var payload interface{}
err = json.Unmarshal(body, &payload)
if err != nil {
if err = json.Unmarshal(body, &payload); err != nil {
http.Error(w, "Failed to parse JSON payload", http.StatusBadRequest)
return
}
// TODO: Do something with the payload
fmt.Fprintf(w, "I got some JSON: %v", payload)
if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil {
panic(err)
}
go func() {
if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil {
log.Println(err)
}
}()
})
}