Server

createManicServer

Bun.serve bootstrap for Manic apps — HTML bundle or string config routes plugins API modes.

createManicServer(options)

Primary export from manicjs/server. Loads ManicConfig (unless overridden), discovers routes when omitted, mounts static/API/plugin handlers, and returns the Bun.serve handle.

~manic.ts
import { createManicServer } from 'manicjs/server';
import app from './app/index.html';

export default await createManicServer({
  html: app,
});

Signature

function createManicServer(options: {
  html: string | (() => string | Promise<string>) | HTMLBundle;
  config?: ManicConfig;
  routes?: RouteInfo[];
  envKeys?: string[];
  startTime?: number;
}): Promise<ReturnType<typeof Bun.serve>>;

Options

FieldPurpose
htmlDev HTMLBundle from import './app/index.html' or raw HTML string / async loader in advanced setups
configSkip loadConfig() — supply frozen config object
routesOverride filesystem discovery — rarely needed
envKeysPublic env names surfaced to window.__MANIC_ENV__ injection paths
startTimeperformance.now() anchor for CLI banner timings

Modes

config.modeBehavior highlights
frontendSPA only · optional dev /sitemap.xml · no Hono API graph
fullstackLoads apiLoaderPlugin, exposes /api, /openapi.json, /.well-known/api-catalog

Deep dive: Server runtime.


Plugins & HTML injection

Plugins run configureServer with addRoute, addLinkHeader, and injectHtml — mirrored concepts to createPlugin (Plugins).


See also

On this page