wasm-serve
wasm-serve is a small web server for testing a web build of your game on
your own computer. Web builds use threads, and browsers only allow that when
the page is served with special headers; opening the HTML file directly, or
serving it with a plain static server, does not work. wasm-serve sends the
right headers.
Common commands
wasm-serve dist/web
wasm-serve dist/web --port 8080
Then open the URL it prints, for example http://localhost:8000/index.html,
in a browser on the same computer. Browsers allow threads on
http://localhost but not on other addresses over plain HTTP, so opening the
page from another device on your network fails.
Options
| Option | Default | Description |
|---|---|---|
DIRECTORY | Looks for a web build in build-wasm-release, build-wasm or the current folder | Folder containing your web build's HTML page. |
--port N | 8000 | Port to listen on. |
--host ADDR | 0.0.0.0 | IPv4 address to listen on. |
/ serves index.html. Files are sent with caching turned off, so a rebuilt
game is picked up when you reload the page. Stop the server with Ctrl+C.
Getting it
wasm-serve comes from an engine build and is not built by default:
cmake --build <engine-build> --target wasm-serve
It is for local testing only. To publish your game, use any HTTPS server that sends the headers listed in Web.
Errors
| Message | What to do |
|---|---|
wasm-serve: cannot listen on HOST:PORT | Another program is using the port. Pick another with --port. |
wasm-serve: no build found here. ... | Pass the folder that holds your .html page. |
| Page loads but the game does not start | Make sure you opened it at http://localhost, not a network address. |