diff --git a/internal/server/handle_api_sync.go b/internal/server/handle_api_sync.go index 1cec945..344ce3f 100644 --- a/internal/server/handle_api_sync.go +++ b/internal/server/handle_api_sync.go @@ -6,7 +6,9 @@ import ( "io" "log/slog" "net/http" + "strings" + "github.com/rjNemo/rentease/internal/constant" "github.com/rjNemo/rentease/internal/service/booking" ) @@ -38,9 +40,17 @@ func handleSync(bs *booking.Service) http.HandlerFunc { slog.Info("created booking from API", slog.String("name", b.Name), slog.String("platform", string(b.Platform))) + scheme := "http" + if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { + scheme = strings.TrimSpace(strings.Split(proto, ",")[0]) + } else if r.TLS != nil { + scheme = "https" + } + bookingURL := fmt.Sprintf("%s://%s%s/%d", scheme, r.Host, constant.RouteBooking, b.ID) + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode("👍"); err != nil { + if err := json.NewEncoder(w).Encode(fmt.Sprintf("👍 %s", bookingURL)); err != nil { slog.Error("failed to write response", slog.Any("error", err)) } }