HTML rendering plugin for Vafast framework
npm install @vafast/htmlHTML rendering plugin for Vafast framework.
- 🚀 Fast HTML Rendering - Efficient HTML response handling
- 🔧 Easy Integration - Simple middleware integration with Vafast
- 📝 JSX Support - Support for JSX elements and streaming
- 🎯 Auto Detection - Automatically detect and handle HTML responses
- ⚡ Streaming Support - Built-in streaming HTML responses
``bash`
npm install @vafast/html
`typescript
import { createServer } from "vafast";
import { html } from "@vafast/html";
const app = createServer();
// Use HTML plugin
app.use(html());
// Define routes
app.get("/", (req) => {
return req.html.html(
);
});app.listen(3000);
`API
$3
Creates an HTML middleware with the specified options.
#### Options
-
contentType - Content-Type header for HTML responses (default: "text/html; charset=utf8")
- autoDetect - Automatically detect HTML responses (default: true)
- autoDoctype - Automatically add DOCTYPE to HTML (default: true)
- isHtml - Custom function to detect HTML content$3
Renders HTML content and returns a Response object.
$3
Creates a streaming HTML response.
Examples
$3
`typescript
app.get("/page", (req) => {
return req.html.html(This is a simple HTML page.
);
});
`$3
`typescript
app.get("/stream", (req) => {
return req.html.stream(({ id }) => Generated at: ${new Date().toISOString()}
, { timestamp: Date.now() });
});
`$3
`typescript
app.use(html({
contentType: "text/html; charset=UTF-8",
autoDetect: true,
autoDoctype: false
}));
`Migration from Elysia
If you're migrating from
@elysiajs/html, the main changes are:1. Import: Change from
import { html } from '@elysiajs/html' to import { html } from '@vafast/html'
2. Usage: Use app.use(html()) instead of app.use(html())
3. API: The API remains the same: req.html.html() and req.html.stream()`MIT