lit-ui-router-ssr / lit-ui-router-ssr / responder
Function: responder()
ts
function responder(
router,
responses,
options?
): Responder;Defined in: packages/lit-ui-router-ssr/src/respond.ts:70
Answers response verdicts on router: settles it on the verdict's subpath, the request's query included, and runs the handler bound to the state it lands on with that transition's resolves and the request. The Response goes out as the handler built it; a HEAD gets it without its body.
It fits the fetch adapter's serveResponse bare: serveResponse: responder(router, responses).
Parameters
| Parameter | Type | Description |
|---|---|---|
router | UIRouter | the server router, its location installed with installServerLocation for the verdict's mount |
responses | BoundResponses | the handlers, keyed by response state name |
options? | SettleOptions | passed to settle |
Returns
the responder; its promise rejects as settle does, so a resolve that throws fails the request before any handler runs
Throws
from the responder, an Error when the landed state has no handler in responses
Example
ts
const responses = {
badge: ({ resolves }) =>
new Response(resolves.svg, { headers: { 'Content-Type': 'image/svg+xml' } }),
} satisfies ResponseHandlers<(typeof routes)[number], { badge: { svg: string } }>;
const handler = createFetchHandler(router, {
serveShell,
serveResponse: (verdict, request) => responder(pageRouter(), responses)(verdict, request),
});