content.handler()

Handle a web-standard Request and dispatch it by path to the Content instance data surface.

content.handler(request)

Handles a single web-standard Request and returns a Response, dispatching by request path. It powers the Vite middleware and is the endpoint createContentClient talks to.

Parameters:

  • request: a Request. The handler strips basePath (default /api/content) from the pathname, then dispatches the remaining path.

Returns: Promise<Response>, a JSON response for matched sections or a structured JSON error (see Errors) for unknown paths and failures.

The first path segment after basePath selects the section:

PathDispatches toResponse body
manifest / manifest.jsoncache.manifest()CacheArtifact
navigation / navigation.jsonnavigation()NavigationItem[]
snapshot/<source> / .jsoncache.snapshot('<source>')CacheArtifact | null
get/<path>get('/<path>', opts)ContentFile | null
list/<json-encoded-sources>list(sources, opts)ContentListFile[]
customa serve handler registered via addServeHandlerhandler-defined
server/api/content/[...path].ts
import { toWebRequest } from 'h3'
import { content } from '~~/server/utils/content'

export default eventHandler((event) => content.handler(toWebRequest(event)))

Errors

Failures return a JSON body of the shape { error, message? } with an appropriate status code, so clients can react without parsing free-form text:

StatuserrorWhen
400bad_requestThe list sources parameter isn't valid JSON.
404not_foundUnknown section, or snapshot requested without a source name.
500internal_errorAn unexpected error while producing the response. The failure is also logged via content.logger.
{ "error": "bad_request", "message": "The list sources parameter must be a JSON-encoded array." }

Usage

server/api/content/[...path].ts
export default eventHandler((event) => content.handler(toWebRequest(event)))