2024-04-17 00:56:47 +09:00

30 lines
578 B
Go

package main
import (
"fmt"
"io"
"net/http"
"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare"
"github.com/syumai/workers/cloudflare/fetch"
)
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
bind := cloudflare.GetBinding("hello")
fc := fetch.NewClient(fetch.WithBinding(bind))
hc := fc.HTTPClient(fetch.RedirectModeFollow)
res, err := hc.Do(req)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
io.Copy(w, res.Body)
})
workers.Serve(handler)
}