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: aRequest. The handler stripsbasePath(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:
| Path | Dispatches to | Response body |
|---|---|---|
manifest / manifest.json | cache.manifest() | CacheArtifact |
navigation / navigation.json | navigation() | NavigationItem[] |
snapshot/<source> / .json | cache.snapshot('<source>') | CacheArtifact | null |
get/<path> | get('/<path>', opts) | ContentFile | null |
list/<json-encoded-sources> | list(sources, opts) | ContentListFile[] |
| custom | a serve handler registered via addServeHandler | handler-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:
| Status | error | When |
|---|---|---|
400 | bad_request | The list sources parameter isn't valid JSON. |
404 | not_found | Unknown section, or snapshot requested without a source name. |
500 | internal_error | An 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)))