30 lines
578 B
Go
Raw Permalink Normal View History

2023-04-09 09:36:27 +09:00
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) {
2024-04-17 00:56:47 +09:00
bind := cloudflare.GetBinding("hello")
2023-04-11 21:35:09 +09:00
fc := fetch.NewClient(fetch.WithBinding(bind))
2023-04-09 09:36:27 +09:00
2024-04-16 23:27:40 +09:00
hc := fc.HTTPClient(fetch.RedirectModeFollow)
2023-04-11 21:35:09 +09:00
res, err := hc.Do(req)
2023-04-09 09:36:27 +09:00
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
io.Copy(w, res.Body)
})
workers.Serve(handler)
}