I started a simple http server on WSL2 to serve simple HTML page at localhost:8081.
I would like to have access to this via localhost:8081 (or whatever the URL is) on the host machine.
I followed the instructions https://docs.microsoft.com/en-us/windows/wsl/compare-versions.
I used ip addr | grep eth0 to find the IP under inet and then I started a simple HTTP server in Python and Julia
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
the python version above works with no issues but the Julia server just doesn't work.
using HTTP
using HTTP: Sockets, @ip_str
HTTP.serve() do request::HTTP.Request
@show request
@show request.method
@show HTTP.header(request, "Content-Type")
@show HTTP.payload(request)
try
return HTTP.Response("Hello")
catch e
return HTTP.Response(404, "Error: $e")
end
end
which opens port 8000 and 8081 for HTTP traffic. Then I went to the host machine and did localhost:8081 and $WSL2VMIP:8081
Neither worked.