Skip to content

Dev

The dev adapter is the building block createCli uses internally — h3 + WebSocket RPC + the author's SPA mounted at the resolved base path. Reach for it directly to mount the dev server inside an existing CLI program (commander, yargs, hand-rolled CAC) or to attach custom middleware to the underlying h3 app.

ts
import { createDevServer } from 'devframe/adapters/dev'
import devframe from './devframe'

const handle = await createDevServer(devframe, {
  port: 7777,
  onReady: ({ origin }) => console.log(`Ready at ${origin}`),
})

// graceful shutdown — SIGINT, hot reload, test teardown
process.on('SIGINT', () => handle.close().then(() => process.exit(0)))

createDevServer returns the underlying StartedServer (origin, port, h3 app, WS server, RPC group, close()) so callers can integrate it into their own process lifecycle.

OptionDefaultDescription
hostdef.cli?.host ?? 'localhost'Bind host.
portresolved via resolveDevServerPortPort to listen on.
flags{}Parsed flag bag forwarded to setup(ctx, { flags }).
distDirdef.cli?.distDirRequired — throws when neither is set.
basePathresolveBasePath(def, 'standalone')Mount path override.
appfresh h3 appPre-configured h3 app to mount onto (custom middleware, auth, extra static assets).
openBrowserresolves from flags.open / def.cli?.openExplicit on/off override. false disables; a string opens that relative path.
onReadyCallback when the WS server is bound.

Port resolution

resolveDevServerPort(def, opts?) resolves a port up-front (to print or log it) before the server starts:

ts
import { resolveDevServerPort } from 'devframe/adapters/dev'

const port = await resolveDevServerPort(devframe, { host: '127.0.0.1' })
// honors def.cli?.port / portRange / random
OptionDefaultDescription
hostdef.cli?.host ?? 'localhost'Bind host (passed to get-port-please for in-use detection).
defaultPortdef.cli?.port ?? 9999Override the preferred port.

Released under the MIT License.