/elysia-html

A plugin for Elysia that add support for returning html

Primary LanguageTypeScriptMIT LicenseMIT

@elysiajs/html

Plugin for elysia that add support for returning html.

Installation

bun add @elysiajs/html

Example

import { Elysia } from 'elysia'
import { html } from '@elysiajs/html'

const page = `<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title>Hello World</title>
    </head>
    <body>
        <h1>Hello World</h1>
    </body>
</html>`

const app = new Elysia()
    .use(html())
    .get('/', () => page)
    .get('/html', ({ html }) => html(page))
    .listen(8080)

API

This plugin detects HTML string and adds html method to Context.

If your response is start with <!DOCTYPE (case insensitive), Content-Type will be set to text/html.

Or if you want to manually return HTML, simply use the newly added html function like this:

app.get('/html', ({ html }) => html(page))