Dev server

motabhai serve rebuilds on every change, reloads the browser and shows build errors over the page, and it serves the admin UI.

motabhai serve

motabhai serve                    # http://127.0.0.1:5000/
motabhai serve --port 8080
motabhai serve --port 0           # pick a free port
motabhai serve --host 0.0.0.0     # let other machines connect; turns the admin off
motabhai serve --output /tmp/site # build somewhere other than public/

The flags are listed in the command line reference.

The server builds the site into the output directory, serves it, and watches the project. It prints the address it serves at, and the admin's. When a file in content/, models/, flowblocks/, templates/, databags/, assets/, themes/ or motabhai.toml changes, it rebuilds incrementally, prints what it rebuilt, and every open page reloads itself. A change that rebuilds nothing does not reload anything. Requests wait for a running rebuild, so you never see a half-built page. Changes to motabhai.toml, such as a new url or theme, apply without a restart.

  • Base path. The site is served under its base path. With url = "https://user.github.io/repo/" it is at http://127.0.0.1:5000/repo/, and / redirects there, so links behave exactly as they will once published.
  • Errors. A build error is printed in the terminal and shown over the page in the browser until it is fixed. The previous output is still served meanwhile.
  • 404. A missing path is answered with the site's own 404.html, if it has one, with status 404. Without one, a short page says nothing is built there.
  • Directories. /about redirects to /about/.
  • Tailwind runs in watch mode, if the site uses it.

The server injects a small live reload script into every HTML page it serves; the files in the output directory do not contain it. The script listens on /__motabhai/events. Responses are sent with Cache-Control: no-store, so the browser never shows an old copy. Build hooks do not run under motabhai serve; see Build hooks.

The admin UI

The dev server also serves an admin UI, http://127.0.0.1:5000/admin/ by default, for editing content in the browser. It is part of the binary and is only served on a loopback address (--host 0.0.0.0 turns it off). The admin UI describes it.