{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package devserver\n\nPackage devserver implements \\`wpix serve\\`: a static file server for a browser game's development build that pushes asset changes to the open page.\n\nUsage:\n\n\twpix serve [--addr :8080] [--assets \u003cdir\u003e] \u003cdir\u003e\n\nIt serves \\\u003cdir\u003e (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.\n\nExit codes: 0 ok, 1 the server failed, 2 usage error.\n\n## Constants\n\n```go\nconst ChangesPath = \"/_weakpixel/changes\"\n```\nChangesPath is the URL path of the event stream.\n\n## Functions\n\n```go\nfunc Run(ctx context.Context, opts Options, stdout io.Writer) error\n```\nRun serves opts.Dir until ctx is done and prints the address to stdout. A directory that does not exist is a usage error; a listener or server that fails is a plain error.\n\n## Types\n\n```go\ntype Options struct {\n\tDir    string // the build directory, served at /\n\tAddr   string // address to listen on\n\tAssets string // asset directory, served under /assets/ and watched; may be empty\n}\n```\nOptions are the arguments of \\`wpix serve\\`.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer serves a build directory and an asset directory and pushes the asset directory's changes to event-stream clients.\n\n```go\nfunc New(ctx context.Context, dir, assets string, interval time.Duration) *Server\n```\nNew returns a Server and, when assets is not empty, starts polling it every interval until ctx ends. The tree is scanned once before New returns, so only changes after that are reported.\n\n```go\nfunc (s *Server) Handler() http.Handler\n```\nHandler returns the HTTP handler: the build at /, the assets under /assets/ and the event stream at [ChangesPath](#ChangesPath).\n\n","path":"github.com/weakpixel/engine/tools/internal/devserver","name":"devserver","synopsis":"Package devserver implements `wpix serve`: a static file server for a browser game's development build that pushes asset changes to the open page.","isRedistributable":true}
