0.4.1 • Published 11 months ago
@yikesable/fastify-async-htm-to-string v0.4.1
Fastify Async Htm To String
Fastify plugin for async-htm-to-string
, which renders a htm tagged template asyncly into a string.
Usage
To render simple HTML fragment
import { fastify } from 'fastify';
const app = fastify();
app.register(import('@yikesable/fastify-async-htm-to-string'));
app.get('/', (_request, reply) => {
reply.render(html`<div>Hi</div>`);
});
To render full HTML page
import { fastify } from 'fastify';
const app = fastify();
const htmlHead = async () => '<!DOCTYPE html><html lang="en">' + await app.render(html`
<head>
<meta charset="utf-8" />
<title>Hello World</title>
</head>
`);
app.register(import('@yikesable/fastify-async-htm-to-string'), { htmlHead });
app.get('/', (_request, reply) => {
reply.renderPage(html`<div>Hi</div>`);
});