1.0.0 • Published 8 months ago

@gtrabanco/elysia-inject-html v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

Description

This is a plugin for elysia that injects html/js code in the response page.

Installation

bun add --exact @gtrabanco/elysia-inject-html

Usage

import { Elysia } from 'elysia';
import { injectHtml } from '@gtrabanco/elysia-inject-html';

const app = new Elysia()
  .use(injectCode({
    selector: 'body'
    code: '<script>alert("Hello World!")</script>'
  }))
  .get('/index.html', () =>
    new Response('<html><body></body></html>', {
      headers: {
        'content-type': 'text/html'
      }
    }))
  .listen(8080);

You can provide multiple code with the same selector by providing an array of strings:

const app = new Elysia()
  .use(injectHtml({
    selector: 'body'
    code: [
      '<script>alert("Hello World!")</script>',
      '<script>alert("Hello World 2!")</script>'
    ]
  }))
  .get('/index.html', () =>
    new Response('<html><body></body></html>', {
      headers: {
        'content-type': 'text/html'
      }
    }))
  .listen(8080);

Known limitations

Currently it is not working if you create two similar plugins or two plugins that call afterHandle because it will fail. This is confirmed until Elysia 0.7.9.

1.0.0

8 months ago

1.0.0-4

8 months ago

1.0.0-3

8 months ago

1.0.0-alpha.2

8 months ago

1.0.0-alpha.1

8 months ago