Skip to content

SaltyAom/kingworld-html

Repository files navigation

@kingworldjs/html

A plugin for kingworld that add support for returning html.

Installation

bun add @kingworldjs/html

Example

import KingWorld from 'kingworld'
import html from '@kingworldjs/html'

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

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

API

This plugin detect html string and add html method to Context.

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

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

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

About

KingWorld plugin that add supports for returning html

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published