Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http server not work #23

Open
LugiaChang opened this issue Oct 7, 2023 · 1 comment
Open

http server not work #23

LugiaChang opened this issue Oct 7, 2023 · 1 comment

Comments

@LugiaChang
Copy link

LugiaChang commented Oct 7, 2023

go code:

package main

import (
	"net/http"

	"github.com/stealthrocket/net/wasip1"
)

func main() {
	listener, err := wasip1.Listen("tcp", "127.0.0.1:3000")
	if err != nil {
		panic(err)
	}

	server := &http.Server{
		Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("Hello, World!"))
			w.WriteHeader(http.StatusOK)
		}),
	}

	if err := server.Serve(listener); err != nil {
		panic(err)
	}
}

dockerfile:

FROM scratch

COPY bin/test.wasm ./test.wasm

CMD ["/test.wasm"]

build:

GOOS=wasip1 GOARCH=wasm go build -o bin/test.wasm  cmd/test/main.go
docker build -t meyoulvcha/wasm-test:v1.0 -f ./build/test/Dockerfile --platform=wasi/wasm .
docker push meyoulvcha/wasm-test:v1.0

docker run:

docker pull meyoulvcha/wasm-test:v1.0
docker run --rm --network host --name=wasm-test --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm meyoulvcha/wasm-test:v1.0

It is not listening 3000 port:
image

I dont know whats wrong. Can someone help me?

@anthdm
Copy link

anthdm commented Dec 24, 2023

expose 3000 should do the trick in your Docker setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants