Skip to content

Commit c4bd2fd

Browse files
authored
Merge pull request #20 from arthurfiorette/patch-1
Migrate to Elysia 0.7 and Kita Html 3.0
2 parents 961c03c + 49a1abf commit c4bd2fd

17 files changed

+690
-533
lines changed

bun.lockb

5.11 KB
Binary file not shown.

example/index.tsx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Elysia, t } from 'elysia'
22
import { html } from '../src'
3+
import { Suspense } from '@kitajs/html/suspense'
34

45
function page({ name }: { name: string }): string {
56
return `
6-
<html lang="en">
7+
<html lang="en" style="background-color: black; color: white;">
78
<head>
89
<title>Hello ${name}!</title>
910
</head>
@@ -15,33 +16,52 @@ function page({ name }: { name: string }): string {
1516
}
1617

1718
// https://elysiajs.com/plugins/html.html#jsx
18-
function tsxPage({ name }: { name: string }): string {
19+
function tsxPage({ name }: { name: string }): JSX.Element {
1920
return (
20-
<html lang="en">
21+
<html lang="en" style={{ backgroundColor: 'black', color: 'white' }}>
2122
<head>
22-
<title>Hello ${name}!</title>
23+
<title>Hello {name}!</title>
2324
</head>
2425
<body>
25-
<h1>Hello ${name}!</h1>
26+
<h1>Hello {name}!</h1>
2627
</body>
2728
</html>
2829
)
2930
}
3031

31-
export function createApp() {
32-
// https://xelysiajs.com/concept/schema.html
33-
const indexSchema = {
34-
params: t.Object({
35-
name: t.String({ default: 'World' })
36-
})
37-
}
32+
async function FakeDatabase({ name }: { name: string }) {
33+
// Sleeps 1 second
34+
await new Promise((resolve) => setTimeout(resolve, 1000))
35+
return <h1>Hello {name}!</h1>
36+
}
3837

38+
function asyncPage(rid: number, { name }: { name: string }): JSX.Element {
3939
return (
40-
new Elysia()
41-
// https://elysiajs.com/plugins/html.html#options
42-
.use(html())
43-
.get('/', ({ params }) => page(params), indexSchema)
44-
.get('/tsx', ({ params }) => tsxPage(params), indexSchema)
45-
.listen(8080)
40+
<html lang="en" style={{ backgroundColor: 'black', color: 'white' }}>
41+
<head>
42+
<title>Hello {name}!</title>
43+
</head>
44+
<body>
45+
{/* https://github.com/kitajs/html#suspense-component */}
46+
<Suspense rid={rid} fallback={<h1>Loading...</h1>}>
47+
<FakeDatabase name={name} />
48+
</Suspense>
49+
</body>
50+
</html>
4651
)
4752
}
53+
54+
// https://xelysiajs.com/concept/schema.html
55+
const indexSchema = {
56+
query: t.Object({
57+
name: t.String({ default: 'World' })
58+
})
59+
}
60+
61+
new Elysia()
62+
// https://elysiajs.com/plugins/html.html#options
63+
.use(html())
64+
.get('/', ({ query }) => page(query), indexSchema)
65+
.get('/tsx', ({ query }) => tsxPage(query), indexSchema)
66+
.get('/async', ({ query, html }) => html(asyncPage, query), indexSchema)
67+
.listen(8080, () => console.log('Listening on http://localhost:8080'))

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@
3636
"format": "prettier --write ."
3737
},
3838
"peerDependencies": {
39-
"@kitajs/html": ">= 2.2.0",
40-
"elysia": ">= 0.6.11"
39+
"@kitajs/html": ">= 3.0.0",
40+
"elysia": ">= 0.7.15"
4141
},
4242
"devDependencies": {
43-
"@types/node": "^20.6.0",
44-
"bun-types": "^1.0.1",
45-
"elysia": "^0.6.23",
46-
"eslint": "^8.49.0",
47-
"rimraf": "^5.0.1",
43+
"@types/node": "^20.7.2",
44+
"bun-types": "^1.0.3",
45+
"elysia": "^0.7.15",
46+
"eslint": "^8.50.0",
47+
"rimraf": "^5.0.5",
4848
"typescript": "^5.2.2"
4949
},
5050
"dependencies": {
51-
"@kitajs/html": "^2.2.1"
51+
"@kitajs/html": "^3.0.0",
52+
"@kitajs/ts-html-plugin": "^1.1.1"
5253
},
5354
"peerDependenciesMeta": {
5455
"@kitajs/html": {
5556
"optional": true
57+
},
58+
"@kitajs/ts-html-plugin": {
59+
"optional": true
5660
}
5761
}
58-
}
62+
}

0 commit comments

Comments
 (0)