- Add POST /e/{endpoint}/requests/{id}/replay endpoint
- Replay re-sends captured method, path, headers, query, body to target URL
- Response includes target status code, headers, body (truncated 64KB)
- SSRF guard: denies replay to private/loopback by default
- Opt-in env var HATCH_ALLOW_PRIVATE_REPLAY=true for local dev
- Server-rendered inspect page at GET /e/{endpoint} with replay button UI
- SSE live stream for new requests (EventSource)
- Mock configuration at PUT /e/{endpoint}/mock
- Store: GetRequest, GetMock, SetMock methods added
- Chi router migration from stdlib ServeMux
- 26 passing tests including replay unit tests and E2E capture-to-replay
Co-Authored-By: Paperclip <noreply@paperclip.ing>
36 lines
664 B
Go
36 lines
664 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/elfoundation/hatch/internal/handler"
|
|
"github.com/elfoundation/hatch/internal/store"
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func main() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
dbPath := os.Getenv("HATCH_DB_PATH")
|
|
repo, err := store.Open(dbPath)
|
|
if err != nil {
|
|
log.Fatalf("hatch: open store: %v", err)
|
|
}
|
|
defer repo.Close()
|
|
|
|
h := handler.New(repo)
|
|
r := chi.NewRouter()
|
|
h.RegisterRoutes(r)
|
|
|
|
addr := fmt.Sprintf(":%s", port)
|
|
log.Printf("hatch starting on %s", addr)
|
|
if err := http.ListenAndServe(addr, r); err != nil {
|
|
log.Fatalf("hatch server error: %v", err)
|
|
}
|
|
}
|