@coherent.js/fastify
v1.0.0-beta.5
Published
Fastify adapter for Coherent.js
Downloads
14
Readme
@coherent.js/fastify
Fastify adapter for Coherent.js.
- ESM-only, Node 20+
- Works with
[email protected] - Designed to pair with
@coherent.js/core
For a high-level overview and repository-wide instructions, see the root README: ../../README.md
Installation
pnpm add @coherent.js/fastify fastify @coherent.js/corePeer dependencies:
fastify>= 4 < 6@coherent.js/core
Exports
Fastify adapter for Coherent.js
Modular Imports (Tree-Shakable)
- Fastify integration:
@coherent.js/fastify - Handler creation:
@coherent.js/fastify
Example Usage
import { setupCoherent } from '@coherent.js/fastify';
import { createHandler } from '@coherent.js/fastify';Note: All exports are tree-shakable. Import only what you need for optimal bundle size.
Quick start
You can use @coherent.js/core rendering inside Fastify route handlers.
JavaScript (ESM):
import Fastify from 'fastify';
import { renderToString } from '@coherent.js/core';
const app = Fastify();
app.get('/', async (_req, reply) => {
const html = await renderToString({ div: { text: 'Hello from Fastify + Coherent' } });
reply.type('text/html').send(html);
});
app.listen({ port: 3000 });TypeScript:
import Fastify, { FastifyRequest, FastifyReply } from 'fastify';
import { renderToString } from '@coherent.js/core';
const app = Fastify();
app.get('/', async (_req: FastifyRequest, reply: FastifyReply) => {
const html = await renderToString({ div: { text: 'Hello TS' } });
reply.type('text/html').send(html);
});
app.listen({ port: 3000 });Development
pnpm --filter @coherent.js/fastify run test
pnpm --filter @coherent.js/fastify run test:watch
pnpm --filter @coherent.js/fastify run typecheck
pnpm --filter @coherent.js/fastify run buildLicense
MIT © Coherent.js Team
