Skip to content

Commit b677567

Browse files
committed
🎉 feat: JSX and detect html tag automatically
1 parent f106ab0 commit b677567

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ export const html = () =>
1414
.derive(({ set }) => ({
1515
sanitize,
1616
html(value: string) {
17-
set.headers['content-type'] = 'text/html; charset=utf8'
18-
19-
return new Response(value, set)
17+
return new Response(value, {
18+
headers: {
19+
'content-type': 'text/html; charset=utf8'
20+
}
21+
})
2022
}
2123
}))
2224
.onAfterHandle(({ set }, response) => {
2325
if (typeof response === 'string' && isHTML(response)) {
2426
set.headers['content-type'] = 'text/html; charset=utf8'
2527

26-
return response
28+
return new Response(response, set)
2729
}
2830
})
2931

test/index.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ describe('HTML', () => {
3232
expect(res.headers.get('Content-Type')).toContain('text/html')
3333
})
3434

35-
it('auto return html in-sensitive', async () => {
36-
const app = new Elysia().use(html()).get('/', () => `<!doCTypE HTML>`)
37-
38-
const res = await app.handle(req('/'))
39-
expect(res.headers.get('Content-Type')).toContain('text/html')
40-
})
41-
4235
it('inherits header', async () => {
4336
const app = new Elysia().use(html()).get('/', ({ html, set }) => {
4437
set.headers.Server = 'Elysia'
4538

46-
return html
39+
return html("<h1>Hi</h1>")
4740
})
4841

4942
const res = await app.handle(req('/'))

0 commit comments

Comments
 (0)