Fastify helpers. The reply is typed as any, so this module does not depend on Fastify. There is no SSE helper: write sseEvent(envelope) to the raw response yourself.
any
sseEvent(envelope)
import Fastify from 'fastify';import { Fragment, Page, Setup } from '@anzaui/engine';import { sendHtml, sendJson } from '@anzaui/engine/adapters/fastify';const fastify = Fastify();const engine = await new Setup({ root: './templates' }).run();fastify.get('/', async (request, reply) => sendHtml(reply, await new Page('/', { title: 'Fastify' }).run(engine)));fastify.get('/card/:id', async (request, reply) => { const { id } = request.params as { id: string }; return sendJson(reply, await new Fragment('feed/card.html', 'feed', { id }).run(engine));});await fastify.listen({ port: 3000 }); Copy
import Fastify from 'fastify';import { Fragment, Page, Setup } from '@anzaui/engine';import { sendHtml, sendJson } from '@anzaui/engine/adapters/fastify';const fastify = Fastify();const engine = await new Setup({ root: './templates' }).run();fastify.get('/', async (request, reply) => sendHtml(reply, await new Page('/', { title: 'Fastify' }).run(engine)));fastify.get('/card/:id', async (request, reply) => { const { id } = request.params as { id: string }; return sendJson(reply, await new Fragment('feed/card.html', 'feed', { id }).run(engine));});await fastify.listen({ port: 3000 });
Fastify helpers. The reply is typed as
any, so this module does not depend on Fastify. There is no SSE helper: writesseEvent(envelope)to the raw response yourself.Example