F: add incoming property example

This commit is contained in:
aki-0421 2024-01-17 17:46:44 +09:00
parent bb2644d33f
commit e5294f4cd2
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A
6 changed files with 53 additions and 0 deletions

3
_examples/incoming/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build
node_modules
.wrangler

View File

@ -0,0 +1,12 @@
.PHONY: dev
dev:
wrangler dev
.PHONY: build
build:
go run ../../cmd/workers-assets-gen
tinygo build -o ./build/app.wasm -target wasm -no-debug ./...
.PHONY: deploy
deploy:
wrangler deploy

View File

@ -0,0 +1,7 @@
module github.com/syumai/workers/_examples/hello
go 1.21.3
require github.com/syumai/workers v0.0.0
replace github.com/syumai/workers => ../../

View File

@ -0,0 +1,2 @@
github.com/syumai/workers v0.1.0 h1:z5QfQR2X+PCKzom7RodpI5J4D5YF7NT7Qwzb9AM9dgY=
github.com/syumai/workers v0.1.0/go.mod h1:alXIDhTyeTwSzh0ZgQ3cb9HQPyyYfIejupE4Z3efr14=

View File

@ -0,0 +1,20 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/syumai/workers"
"github.com/syumai/workers/cloudflare/incoming"
)
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
p := incoming.NewProperties(req.Context())
buf, _ := json.Marshal(p)
fmt.Fprintf(w, "%s", string(buf))
})
workers.Serve(handler)
}

View File

@ -0,0 +1,9 @@
name = "incoming"
main = "./build/worker.mjs"
compatibility_date = "2022-05-13"
compatibility_flags = [
"streams_enable_constructors"
]
[build]
command = "make build"