Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gtrabanco/elysia-inject-html
https://github.com/gtrabanco/elysia-inject-html
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gtrabanco/elysia-inject-html
- Owner: gtrabanco
- License: other
- Created: 2023-09-21T22:54:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-21T13:09:30.000Z (7 months ago)
- Last Synced: 2024-11-14T15:55:12.782Z (29 days ago)
- Language: TypeScript
- Size: 82 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-elysia - Inject HTML - So simple plugin to inject HTML code in HTML files. (Plugins)
README
# Description
This is a plugin for elysia that injects html/js code in the response page.
# Installation
```bash
bun add --exact @gtrabanco/elysia-inject-html
```# Usage
```js
import { Elysia } from 'elysia';
import { injectHtml } from '@gtrabanco/elysia-inject-html';const app = new Elysia()
.use(injectCode({
selector: 'body'
code: 'alert("Hello World!")'
}))
.get('/index.html', () =>
new Response('', {
headers: {
'content-type': 'text/html'
}
}))
.listen(8080);
```You can provide multiple code with the same selector by providing an array of strings:
```js
const app = new Elysia()
.use(injectHtml({
selector: 'body'
code: [
'alert("Hello World!")',
'alert("Hello World 2!")'
]
}))
.get('/index.html', () =>
new Response('', {
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.