Node middleware
Serve the docs from Express, Connect, Fastify, Nitro or any server that takes Connect-style middleware.
yaakdocMiddleware serves the docs from a Node server: Express, Connect, Fastify (with @fastify/middie), Nitro and others.
npm i yaakdocimport express from "express";
import { yaakdocMiddleware } from "yaakdoc";
const app = express();
app.use(await yaakdocMiddleware({ path: "/docs", export: "./yaak.json" }));
app.listen(3000);- Development. Unless
NODE_ENVisproduction(or you passdev: false), it serves the live dev server. HMR uses its own WebSocket port; passhmr: { server }to share your HTTP server instead. - Production. It serves a built site from
config.outDir. Build it ahead of time withyaakdoc build --base /docs/, or passbuild: trueto build when the middleware is created. - Other requests. Anything outside
pathis passed on withnext().app.use("/docs", ...)works too.
The middleware has a close() method that stops the dev server.
Options
| Option | Description |
|---|---|
path | Where the docs are served. Default: /docs. It takes precedence over config.base. |
config | yaakdoc config, merged over yaakdoc.config.* if there is one. Paths are relative to cwd. |
export | Path of the Yaak export. Shorthand for config.export. By default, yaakdoc.json, then yaak.json, is looked up in cwd. |
cwd | Project directory. Default: process.cwd(). |
configFile | An explicit config file, or false to not look for one. |
publicDir | A folder copied to the docs' root as is. Default: none. |
dev | Serve the live dev server. Default: true unless NODE_ENV is production. |
build | Build the site when the middleware is created (production only). |
hmr | Vite HMR options, e.g. { server } to share your HTTP server. |
For the lower-level building blocks, see the Node API.