Merge branch 'main' of git-ssh.tornberg.me:mats/go-cart-actor
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 33s
Build and Publish / BuildAndDeploy (push) Successful in 3m2s

This commit is contained in:
matst80
2024-11-16 10:15:31 +01:00
4 changed files with 18 additions and 38 deletions

View File

@@ -63,8 +63,9 @@ 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("Cache-Control", "no-cache")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("X-Pod-Name", s.pod_name)
w.Header().Set("Access-Control-Allow-Origin", "https://tornberg.me")
if result.StatusCode != 200 {
log.Printf("Call error: %d\n", result.StatusCode)
if result.StatusCode >= 200 && result.StatusCode < 600 {
@@ -246,7 +247,8 @@ func (s *PoolServer) HandleCheckout(w http.ResponseWriter, r *http.Request) erro
buf.ReadFrom(res.Body)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Pod-Name", s.pod_name)
w.Header().Set("Access-Control-Allow-Origin", "https://tornberg.me")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(res.StatusCode)
w.Write(buf.Bytes())
@@ -286,6 +288,12 @@ func (a *PoolServer) RewritePath(w http.ResponseWriter, r *http.Request) {
func (s *PoolServer) Serve() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/", s.RewritePath)
mux.HandleFunc("OPTIONS /", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, 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("POST /{id}", ErrorHandler(s.HandleAddRequest))