28 lines
608 B
Go
Raw Normal View History

2024-01-17 17:46:44 +09:00
package main
import (
"encoding/json"
"net/http"
"github.com/syumai/workers"
2024-01-23 13:01:33 +09:00
"github.com/syumai/workers/cloudflare/fetch"
2024-01-17 17:46:44 +09:00
)
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
2024-01-23 13:01:33 +09:00
p, err := fetch.NewIncomingProperties(req.Context())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
2024-01-17 17:46:44 +09:00
2024-01-18 21:43:17 +09:00
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(p); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
2024-01-18 21:43:17 +09:00
return
}
2024-01-17 17:46:44 +09:00
})
workers.Serve(handler)
}