Check out some of my articles on dev.to and Medium.
Some of my talks (in french ๐ซ๐ท) are available on this Youtube playlist.
Cheers ๐ป
Embed your Go HTTP handlers in a ServiceWorker and emulate an HTTP server!
License: Apache License 2.0
Check out some of my articles on dev.to and Medium.
Some of my talks (in french ๐ซ๐ท) are available on this Youtube playlist.
Cheers ๐ป
hi, trying to run the hello example.
In go-wasm-http-server/docs/hello
GOOS=js GOARCH=wasm go build -o api.wasm .
but i am stuck here:
../../response_recorder.go:19:10: undefined: js.Wrapper
Study the possibility of using ReadableStream for the JS response.
can we access the http server in wasm from other client by using url like http://127.0.0.1:8080/api/v1?
Very cool project. I've been trying to figure out how to integrate wasm into github.com/micro/micro and I think you've given me some good ideas. Do you have an example demo running anywhere?
To allow service in client and server to push CDC updates when data sources change.
Create, Update, Delete are the ops.
namespace topic that maps to json fragment is the scope of the payload.
client will then update cache of json using that scope.
later when templates are introduced these can also be pushed. Just need CDC on server file system. At the moment html templates are not used. Scoping it a xml scope instead of json obviously.
when use golang direct run,it's perfect:
https://user-images.githubusercontent.com/342509/128476357-3f6f97de-7f09-4b16-97b7-39571450390c.mov
package main
import (
"fmt"
"net/http"
"time"
)
func main() {
http.HandleFunc("/wawawa", func(res http.ResponseWriter, req *http.Request) {
flusher := res.(http.Flusher)
res.Header().Set("Content-Type", "text/html")
fmt.Fprintf(res, "<!doctype html>\n<html><head><title>test</title></head><body>")
for i := 1; i <= 50; i++ {
fmt.Fprintf(res, "<p>Chunk #%d</p>\n<script>console.log(new Date())</script>\n", i)
// perfect
flusher.Flush()
time.Sleep(500 * time.Millisecond)
}
fmt.Fprintf(res, "</body>\n</html>")
})
http.ListenAndServe(":8080", nil)
select {}
}
but with wasm, it's not work:
https://user-images.githubusercontent.com/342509/128476360-f9d80484-c6e4-4bb8-805d-5fc4273727e2.mov
package main
import (
"fmt"
"net/http"
"time"
wasmhttp "github.com/nlepage/go-wasm-http-server"
)
func main() {
http.HandleFunc("/wawawa", func(res http.ResponseWriter, req *http.Request) {
flusher := res.(http.Flusher)
res.Header().Set("Content-Type", "text/html")
fmt.Fprintf(res, "<!doctype html>\n<html><head><title>test</title></head><body>")
for i := 1; i <= 50; i++ {
fmt.Fprintf(res, "<p>Chunk #%d</p>\n<script>console.log(new Date())</script>\n", i)
// not work, 25 s later
flusher.Flush()
time.Sleep(500 * time.Millisecond)
}
fmt.Fprintf(res, "</body>\n</html>")
})
wasmhttp.Serve(nil)
select {}
}
This looks interesting! Just want to make sure I comprehend what it does before diving in.
Suppose I have an application that calls a third party JS library function that expects to fetch a file from a server, say,
MidiJS.play(URL) // where the server at URL generates and returns a midi file to be played
Can I use go-wasm-http-server
in a Go wasm app that generates the midi file content locally in the user's browser to provide a pseudo URL that returns the generated content to the JS call?
Really cleanly done @nlepage
If your interested I will be adding the following:
Pleas feel free to comment.
Is your feature request related to a problem?
run go server build with tiny go in docker wasm container
Describe the solution you'd like
Hi, i found this article about how to run wasm docker with a rust server example:
docker-wasm-technical-preview
I would like to run a go server in a wasm container so i found your package
but i can't make a wasm server with go working in a wasm container
do you know how i can do this or if it's possible ?
Thanks
step to reproduce:
first we need to install docker preview version from documentation
main.go
package main
import (
"encoding/json"
"fmt"
"net/http"
wasmhttp "github.com/nlepage/go-wasm-http-server"
)
func main() {
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
params := make(map[string]string)
if err := json.NewDecoder(req.Body).Decode(¶ms); err != nil {
panic(err)
}
res.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(res).Encode(map[string]string{
"message": fmt.Sprintf("Hello %s!", params["name"]),
}); err != nil {
panic(err)
}
})
wasmhttp.Serve(nil)
select {}
}
build command
tinygo build -o main.wasm -target=wasi main.go
Dockerfile
FROM scratch
COPY main.wasm /main.wasm
EXPOSE 80
ENTRYPOINT [ "main.wasm" ]
build image command
docker buildx build --platform wasi/wasm32 -t go-http .
if you get an error uninstall docker and reinstall preview version from documentation
run container command
docker run -dp 80:80 --name=go-http --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm32 go-http
I have the files used in the /docs/hello
folder.
api.go
index.html
sw.js
Using the prebuilt wasm from the folder works, but if I try to build the Go source code:
GOOS=js GOARCH=wasm go build -o api.wasm .
The example does not alert you.
Also, if it helps:
go get
go version go1.13.8 linux/amd64
Try tinygo to reduce overhead.
Json works but not gob encoding btw.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.