Skip to content

Dev Server (Live Reload)

gmx dev is the development counterpart to gmx run. It compiles and launches your app, then watches your component and all of its .gmx dependencies. On every change it rebuilds and, when the build succeeds, restarts the app and reloads the browser automatically — no manual rebuild, no manual refresh.

DATABASE_URL="app.db" gmx dev app.gmx
gmx dev app.gmx
        ├── compiles app.gmx → temporary binary
        ├── runs it on a random free port
        ├── serves a proxy on :8080 (public)
        │      └── injects a live-reload script into every HTML page
        └── watches app.gmx + every imported .gmx
               └── on change → rebuild → restart → reload browser

How it works

gmx dev runs your app behind a small reverse proxy:

  • The proxy listens on the public port (default :8080) and forwards requests to your app, which runs on a random free port.
  • Live reload is injected automatically. The proxy adds a tiny EventSource client to every HTML response that connects to the /__gmx_reload endpoint. When a rebuild succeeds, the proxy pushes a reload event and the browser calls location.reload().
  • Dependency watching is recursive. If app.gmx imports components/TaskItem.gmx, which imports components/Badge.gmx, all three are watched. Saving any of them triggers a rebuild.
  • Debouncing coalesces bursts of file events (editors often write a file several times per save) into a single rebuild.

Error overlay

When a build fails — a syntax error, a type error, anything the compiler or go build rejects — the previously running app is left untouched so you never lose your session. The browser instead shows a readable overlay with the compiler output:

BUILD FAILED
parser errors:
  script parsing: line 12: expected next token to be {, got EOF instead

Fix the error and save; the next successful build clears the overlay and reloads the page automatically.

Flags

Flag Default Description
--port N 8080 Public port for the dev server.
gmx dev --port 3000 app.gmx

Run gmx dev -h for the full usage message.

Choosing the app port

The compiled app reads the PORT environment variable and falls back to 8080 when it is unset — so gmx build and gmx run are unchanged. gmx dev uses this to run your app on a random free port behind the proxy. You can rely on the same variable in production:

PORT=9000 ./app        # a plain built binary, listening on :9000

Clean shutdown

Press Ctrl-C (or send SIGINT/SIGTERM). gmx dev stops the child process — and its whole process group — before exiting, so no orphaned server is left holding the port.

When to use gmx run vs gmx dev

gmx run gmx dev
Rebuild on change
Browser live reload
Compile-error overlay
Reverse proxy
Best for one-off runs active development