Skip to content

Dev server

hamur dev is the dev server (Getting started shows how to start it). Besides serving pages, it tells you what goes wrong and where: browser console calls in the terminal, the server log lines of a request in the browser, one line for each server fetch, a badge with the route's render mode, slow-call warnings and a report for a page that does not hydrate cleanly. Each of these is a devServer key. All of them are for hamur dev only: a build holds none of the code.

The keys

The full meaning, error messages and edge cases of each key are in the configuration table. This is the list of what reports and records, with the defaults.

KeyDefaultWhat it does
devServer.consoletrueprints the browser's console calls in the terminal, with the source-mapped first frame. "warn" and "error" forward fewer levels, false none
devServer.ssrLogstruethe browser console shows the server log lines of the document request as one collapsed [ssr] group
devServer.logFetchestrueone indented line under a request's log line for each server-side $fetch and ctx.fetch. { fullUrl: true } prints the whole URL
devServer.indicator{ position: "bottom-left" }the badge with the server state and <route name> · <mode>; false draws none. With @hamur/devtools the text is in its toolbar
devServer.slowWarning4000milliseconds after which a loader, middleware, app plugin setup or async-data handler that is still running logs a warning; false sets no timer
devServer.chromeWorkspacetrueanswers the file that lets Chrome DevTools map the project folder as a workspace (Chrome workspace)
devServer.updateCheckfalseasks the npm registry at most once per 24 hours for a newer hamur and prints a line when there is one
devServer.hydrationMismatch"overlay"reports a page whose first browser render differs from the server's HTML (below)
devServer.timingtruewrites performance.measure entries for plugins, hooks, middleware, loaders, navigations and hydration (below)
devServer.inspectfalserecords every step of the transform chain for /_hamur/inspect and the devtools Inspect tab (Devtools)
devServer.mcptrueserves the dev MCP endpoint for coding agents at POST /_hamur/dev/mcp (below)
ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "html",
  devServer: { console: "warn", logFetches: { fullUrl: true }, slowWarning: 2000, hydrationMismatch: "console" },
})

These keys set where the server listens, which files it watches and what it runs. The rest of this page says more on each.

KeyDefaultWhat it does
devServer.port3000the port; --port and the PORT variable win over it. A port you set is never replaced: if it is busy, the start fails
devServer.host"localhost"the address to listen on; --host wins. "0.0.0.0" listens on every interface and prints a Network: line for each address
devServer.openfalseopens the Local: address once when the server first serves: true opens /, a path starting with / opens that path of the app. --open wins. devServer.open must be a boolean or a path starting with "/" (got "about")
devServer.httpsunsettrue serves HTTPS with a self-signed certificate Hamur writes; { key, cert, ca?, passphrase? } uses yours, and wins over --https (HTTPS)
devServer.allowedHosts[]extra host names the server answers, true for every host (configuration)
devServer.hmrtruefalse turns off Bun's hot replacement; every change to a file the browser loads reloads the page (HMR in app code)
devServer.prefetchfalsetrue keeps hover and focus data prefetch as in a build; by default only chunks are prefetched, since every load runs on a server that recompiles
devServer.tasksfalseruns scheduledTasks under hamur dev (Tasks)
devServer.handlers[]request handlers that exist in hamur dev only, as { route: "/__mock/", handler: "./dev/mock.ts" }; a build ignores them
devServer.warmup[]paths of the app to request after Local: (Warmup)
devServer.watch{ poll: false }poll is a number of milliseconds, at least 50 (Watching with polling)

The top-level logLevel and debug keys set what the [hamur] lines say; see Debugging.

ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "html",
  devServer: {
    port: 4000,
    host: "0.0.0.0",
    open: "/docs",
    allowedHosts: [".ngrok.app"],
    warmup: ["/", "/pricing"],
    watch: { poll: 300 },
    tasks: true,
    handlers: [{ route: "/__mock/", handler: "./dev/mock.ts" }],
  },
})

Starting and stopping

hamur dev --background starts the server detached and returns once it serves, printing the Local: URL, the dev MCP URL and the log file .hamur/dev.log; the server's output goes to that file. Every hamur dev keeps .hamur/dev.lock with its pid, url, port and mcp URL, so a script or an agent can find it: hamur dev status prints running at <url> (exit 0) or not running (exit 1), hamur dev logs [-f] [-n <count>] prints the end of the log, and hamur dev stop ends the server and frees its port. A second hamur dev while one runs prints already running at <url> and exits 0, and hamur cleanup refuses to remove .hamur until it stops.

A start prints these lines, each with the [hamur] prefix, in this order: Local: <url>; one Network: <url> per address under a wildcard host; Public: <origin> when app.origin or HAMUR_ORIGIN is set; the QR code with --qr; Debugger: <url> with --inspect; press h + enter to show help on a terminal; and the HTTPS notice with --https.

When the default port is busy, the server takes the next free one, up to 10 on, and logs Port 3000 is in use, using 3001. A port you chose (--port, PORT or devServer.port) is never replaced, and a busy one fails: Port 3411 is in use; pick another with --port. The command ends with exit code 0 after SIGINT, SIGTERM or the q shortcut, and with 1 for a start that fails.

hamur dev restarts when hamur.config.* (or the --config file), bunfig.toml or a .env file changes. A server file edit builds the next generation while the old one finishes its requests. A broken config logs its error and waits for the next save. --clear-screen clears the terminal before each restart's output. The first start and output that is not a terminal are left alone.

Open the app in a browser

--open opens the Local: address once, when the server first serves. --open=/about opens that path of the app. A restart does not open it again.

devServer.open does the same from the config, and the flag wins. The BROWSER variable names another program to open it with, and BROWSER=none opens nothing.

Open the app on a phone

hamur dev --host --qr listens on every network interface and prints a QR code of the first Network: address. Scan it with a phone on the same network.

--qr without a wildcard host fails: --qr needs a wildcard host; pass --host or set devServer.host to "0.0.0.0".

Shortcuts

On a terminal, hamur dev reads one shortcut per line, so type the letter and press Enter.

KeyDoes
rrestarts the server
uprints the addresses again
oopens the app in your browser
cclears the terminal
qquits, with exit code 0
hlists the shortcuts

Any other text logs Unknown shortcut "x"; press h + enter to show help. Shortcuts are off when CI is set or standard input is not a terminal. HAMUR_DEV_SHORTCUTS=1 turns them on and HAMUR_DEV_SHORTCUTS=0 off.

sh
HAMUR_DEV_SHORTCUTS=1 hamur dev
HAMUR_DEV_SHORTCUTS=0 hamur dev

The dev MCP endpoint for coding agents

hamur dev answers the Model Context Protocol at POST <app.baseURL>_hamur/dev/mcp, so a coding agent asks the running app what is wrong instead of reading the terminal. It is stateless and speaks the two protocol revisions the app's own MCP endpoint speaks. Its seven tools:

ToolInputAnswers
get_errorsnonethe current build error, the last server render error of each path (20 at most) and the last 20 browser errors, newest first, each with file (relative to the root), line, column and the code frame
get_logsreqId?, level?, limit? (1 to 1000, default 100)the dev server's last log records, oldest first, redacted as the logger redacts
get_routesnonethe pages, server routes and route rules with their files, as GET /_hamur/routes
get_pagepaththe page the router matches, without rendering it: params, the chain of page files, layout, loaders, middleware and route rules
compile_routepathrenders GET <path> in process and answers its status, time, redirect, <head> and the errors the render produced
get_confignonethe resolved config, with every key the logger redacts and every private runtimeConfig value, every storage and devStorage mount option but driver, and every devServer.https value written [redacted]
get_handlersnoneevery handler in server/, with its name, file, method, route and kind

path is an app path such as /blog/1, without app.baseURL. The endpoint takes the rule of the devtools routes: a request from another site gets 403 Cross-site request to /_hamur/dev/mcp refused, and one from another device needs the dev token. devServer.mcp: false turns it off, and a build has none of it.

HTTPS

hamur dev --https, or devServer.https: true, serves over HTTPS with a certificate Hamur makes for you: an ECDSA P-256 key and a self-signed certificate for localhost, 127.0.0.1, ::1 and the --host value (under a wildcard host, each network address). They are written to .hamur/dev/cert/key.pem, readable by you only, and cert.pem, valid for 30 days, and reused until a day before they expire or until the names change. hamur dev prints https:// addresses and logs [hamur] HTTPS with a self-signed certificate; the browser warns until you trust .hamur/dev/cert/cert.pem. Hamur never adds the certificate to a trust store.

To use your own, set devServer.https to { key, cert }: each of key, cert and ca is PEM text or a path to a PEM file, resolved from the app root, and passphrase unlocks an encrypted key. This wins over --https. Anything else is devServer.https must be a boolean or { key, cert, ca?, passphrase? } (got "yes").

ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "react",
  devServer: {
    port: 3000,
    https: { key: "./certs/key.pem", cert: "./certs/cert.pem" },
  },
})

hamur preview uses the same key: a bun or static build is served over HTTPS, and the node preset prints The node preset serves HTTP; TLS belongs to the proxy in front of it.

A backend in dev

There is no devServer.proxy. The proxy route rule already forwards as a reverse proxy: it drops host (the upstream's own comes from the target), follows no redirect, keeps the upstream's Set-Cookie, and answers 502 with a logged cause when the upstream cannot be reached. To have the rule in hamur dev only, put it in $development (Blocks per mode).

ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "html",
  $development: {
    routeRules: { "/backend/**": { proxy: "http://127.0.0.1:8080/**" } },
  },
})

/backend/x?y=1 reaches http://127.0.0.1:8080/x?y=1. hamur build, generate and preview read no $development block, so the output holds no trace of it. WebSocket upgrades are not relayed: a page that needs the backend's socket connects to the backend's own address, and the backend allows it by Origin.

The same goes for headers: there is no devServer.headers. A headers entry of a routeRules key applies in hamur dev to pages, server routes, files in public/ and imported assets, and in a build, so cross-origin-opener-policy is the same in both. Bun answers /_bun/* itself, so those paths carry no rule header.

Behind a proxy or a tunnel

With app.origin or HAMUR_ORIGIN set, hamur dev logs Public: <origin>, builds URLs from that origin as a build does, and admits that origin's host and its Origin, as it does the --host value. That, and not a devServer.url key, is how the server is reached through a tunnel or a devcontainer's forwarded port. Bun refuses a Host name outside localhost, *.localhost and IP addresses for /_bun/*, so have the proxy rewrite Host to localhost, or the client bundle and the hot-update socket answer 403.

Warmup

After Local: and after each restart, hamur dev requests its own /_hamur/shell and the client entry that page names once, so the first page you open does not wait for Bun to bundle it. devServer.warmup lists more paths of the app, below app.baseURL, to request then, one at a time, such as ["/", "/pricing"]. Each renders on the server and runs its load and middleware like a visit, so list pages that only read. The requests carry x-hamur-warmup: 1 and are left out of the request log, the metrics and the traces. One that fails logs Warmup /pricing failed: status 500 at the debug level. devServer.warmup must be an array of paths (got "/") and devServer.warmup entry "pricing" must start with "/" are the two ways the key is refused.

Watching with polling

fs.watch sees no change made through a network share, a container bind mount or a Windows file under WSL, and some file systems report events late. devServer.watch: { poll: <ms> } replaces the events with a poll: every poll milliseconds the watcher walks the app's root and each layer's, with the ignore rules of a build (node_modules, .hamur, .output, .git, ignore and .hamurignore), and compares each file's modification time and size with the last walk. A change goes through the same 50 ms debounce as an event. poll is an integer of at least 50, or false: devServer.watch.poll must be an integer of at least 50 milliseconds or false (got 10).

A tree of 2000 files walks in under a millisecond, so 300 is cheap; set a larger value for a larger tree. Bun's bundler watches the client files with its own watcher, which the poll does not reach, so when the poll sees a client file change that the bundler did not, Hamur touches the file to give Bun an event, and reloads the page when the touch fails.

Under WSL, with the app below /mnt/c/ or another drive and no poll, hamur dev logs once [hamur] Files under /mnt/c are not watched reliably from WSL; set devServer.watch.poll: 300. There is no devServer.watch.ignore; the top-level ignore and .hamurignore are the one list of what the watcher skips. A value for your machine and not the repository goes in ~/.hamurrc (CLI):

txt
# ~/.hamurrc
devServer.watch.poll=300

Timing

With devServer.timing on, the browser wraps each app plugin setup, app hook call, route middleware, loader run, navigation, hydration and adapter update in performance.measure. The entries sit on a Hamur track of Chrome's Performance panel and are named hamur:plugin:<name>, hamur:hook:<name>, hamur:middleware:<name>, hamur:loader:<route> and hamur:navigation. A loader's ctx.fetch sends a traceparent header to the same origin, so the devtools Timeline tab nests the server spans of that request under the loader. false writes no measure and the Timeline shows no client events. It is the Hamur form of Nuxt's experimental.browserDevtoolsTiming.

Hydration mismatch report

Hydration attaches the library to the HTML the server sent. When the first render in the browser produces other markup, the library may warn, repair the page silently or leave it broken, and each library says it differently. hamur dev compares the markup itself and reports the first node that differs, the same way for all six adapters.

A report does three things, once for each component and path on the page:

  • prints [hamur] hydration mismatch in <component> at <path> in the browser console, and prints it in the terminal with the route, as (<route>);
  • adds one to the number window.__hamur_hydration and to the list the devtools page hook returns from hydration();
  • with "overlay", opens a panel at the bottom of the page that shows the server and the client markup of the node side by side, with the difference marked and the component file as a link that opens in your editor (Open in editor).

devServer.hydrationMismatch: "console" gives the lines and the counter without the panel. false reports nothing, and the library's own warnings print as they did before.

What each adapter reports differs because each library detects differently:

AdapterReports from
reactits recoverable hydration error. It shows in this panel, not in the error overlay
vueits hydration warnings and the element they name
preact, sveltethe DOM after hydrating, compared with the server markup
htmlits render string, compared with the server markup
solidonly a node it cannot find while hydrating (its own Hydration Mismatch error). Solid keeps the server's text and attributes, so a text or attribute difference in a Solid app gives no report
angularits NG0500, NG0501, NG0502 and NG0509 hydration errors, which name an element that differs or is missing. Angular rewrites the server's text, so a text difference gives no report

A typical cause and its fix

The usual cause is a value that the server and the browser compute differently: the time, a random number, a locale, a typeof window branch, a browser extension that edits the page before hydration. The fix is to render the same value in the first browser render and show the browser's value after the app has mounted. Every adapter has useHydrated(), which is false on the server and in the hydration render, and ClientOnly, which writes its fallback there (Islands and streaming).

react. <p>{new Date().toLocaleTimeString()}</p> prints the server's time and then the browser's, and React reports a text mismatch. ClientOnly renders the fallback until the app has mounted.

tsx
import { ClientOnly } from "@hamur/adapter-react"

export default function Clock() {
  return (
    <p>
      <ClientOnly fallback="--:--">{new Date().toLocaleTimeString()}</ClientOnly>
    </p>
  )
}

vue. {{ new Date().toLocaleTimeString() }} in the template fails the same way. useHydrated() is a Ref.

vue
<script setup lang="ts">
import { useHydrated } from "@hamur/adapter-vue"

const hydrated = useHydrated()
</script>

<template>
  <p>{{ hydrated ? new Date().toLocaleTimeString() : "--:--" }}</p>
</template>

preact. A time or a Math.random() id in the first render differs. useHydrated() is a boolean.

tsx
import { useHydrated } from "@hamur/adapter-preact"

export default function Clock() {
  const hydrated = useHydrated()
  return <p>{hydrated ? new Date().toLocaleTimeString() : "--:--"}</p>
}

svelte. A window.innerWidth branch in the markup differs. useHydrated() is an object with current.

svelte
<script lang="ts">
  import { useHydrated } from "@hamur/adapter-svelte"

  const hydrated = useHydrated()
</script>

<p>{hydrated.current ? new Date().toLocaleTimeString() : "--:--"}</p>

solid. Solid reports a node that the browser render has and the server HTML does not, such as an element that only the browser render creates, behind a typeof window check. useHydrated() is an accessor, so the element appears after the mount and the hydration finds the nodes it expects.

tsx
import { useHydrated } from "@hamur/adapter-solid"

export default function Clock() {
  const hydrated = useHydrated()
  return <p>{hydrated() ? new Date().toLocaleTimeString() : "--:--"}</p>
}

html. A render function that calls Date.now() writes another string in the browser. ClientOnly takes a function and the fallback, and the browser paints the function's result at once.

ts
import { ClientOnly } from "@hamur/adapter-html"

export default function Clock(): string {
  return `<p>${ClientOnly(() => new Date().toLocaleTimeString(), { fallback: "--:--" })}</p>`
}

The report comes from the dev client alone. A production client has no part of it, and reportHydrationMismatch of hamur/adapter/dev is for adapter authors.

Inside your own Bun server

An app that already has a Bun.serve of its own, such as an API, can serve its Hamur pages from that server in development instead of a second port. createDevMiddleware of hamur/kit returns the dev server as parts: spread dev.routes into your routes, pass dev.websocket as your websocket, and ask dev.fetch first in your fetch.

ts
import { createDevMiddleware } from "hamur/kit"

const dev = await createDevMiddleware()

Bun.serve({
  development: { hmr: true },
  routes: { ...dev.routes, "/health": new Response("ok") },
  async fetch(request, server) {
    const answer = await dev.fetch(request, server)
    if (answer === null) return
    return answer ?? new Response("host")
  },
  websocket: dev.websocket,
})

process.on("SIGINT", () => void dev.close().finally(() => process.exit(0)))

dev.fetch resolves a Response for Hamur's requests (the app's pages, server routes, public/ files, imported assets and /_hamur/*), null when it upgraded the request to a WebSocket, which your fetch answers with nothing, and undefined for any other path, which your server answers. Routes of your own in routes, such as /health, never reach it. A server with sockets of its own calls dev.websocket only for sockets whose ws.data.hamur is true.

Start the server with the config file Hamur writes, since Bun reads the dev bundler's plugins only from there:

sh
bun --config=.hamur/dev/bunfig.toml server.ts

Without it the first run stops with createDevMiddleware needs Bun to start with the generated config: run bun --config=.hamur/dev/bunfig.toml <file> (the first run also writes the file). Page and server code edits update as in hamur dev. An edit of hamur.config.*, .env or a module file needs a restart of your server, and until then dev.fetch answers 503 with The Hamur config changed; restart the host.