Skip to main content

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​

OptionDefaultDescription
DIRECTORYLooks for a web build in build-wasm-release, build-wasm or the current folderFolder containing your web build's HTML page.
--port N8000Port to listen on.
--host ADDR0.0.0.0IPv4 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​

MessageWhat to do
wasm-serve: cannot listen on HOST:PORTAnother 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 startMake sure you opened it at http://localhost, not a network address.