Documentation
¶
Overview ¶
Package devserver implements `wpix serve`: a static file server for a browser game's development build that pushes asset changes to the open page.
Usage:
wpix serve [--addr :8080] [--assets <dir>] <dir>
It serves <dir> (the page and game.wasm) at /, and the --assets directory under /assets/, both with "Cache-Control: no-cache" so the browser revalidates instead of reusing a stale body after a save. GET /_weakpixel/changes is an event stream (server-sent events): the server polls the modtime and size of the asset tree every 250 ms, where a stat is cheap, and sends one `data: {"paths": [...]}` event per batch of changed files. Paths are asset keys: slash-separated, relative to the asset directory. A browser cannot list directories, so the server also answers /assets/assets.catalog.json from the asset directory (scanned on every request, so new files show after a page reload) unless the directory has its own. A game turns the stream into hot reload with httpfs.WatchChanges and game.Config.AssetChanges.
Exit codes: 0 ok, 1 the server failed, 2 usage error.
Index ¶
Constants ¶
const ChangesPath = "/_weakpixel/changes"
ChangesPath is the URL path of the event stream.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
Dir string // the build directory, served at /
Addr string // address to listen on
Assets string // asset directory, served under /assets/ and watched; may be empty
}
Options are the arguments of `wpix serve`.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves a build directory and an asset directory and pushes the asset directory's changes to event-stream clients.