forked from nanojsx/nano-jsx-deno-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
56 lines (44 loc) · 1.21 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { h, renderSSR, Helmet } from './deps.ts'
import { Application, Router } from './deps.ts'
import { Comments } from './components/Comments.tsx'
import { Hello } from './components/Hello.tsx'
const comments = ['Hey! This is the first comment.', 'Hi, from another comment!']
const App = () => (
<div>
<Helmet>
<title>Nano JSX SSR</title>
<meta name="description" content="Server Side Rendered Nano JSX Application" />
</Helmet>
<Hello />
<h2>Comments</h2>
<div id="comments">
<Comments comments={comments} />
</div>
</div>
)
const ssr = renderSSR(<App />)
const { body, head, footer } = Helmet.SSR(ssr)
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${head.join('\n')}
</head>
<body>
${body}
${footer.join('\n')}
</body>
</html>`
const router = new Router()
router.get('/', context => {
context.response.body = html
})
const app = new Application()
app.use(router.routes())
app.use(router.allowedMethods())
app.addEventListener('listen', ({ port }) => {
console.log(`Listening on: http://localhost:${port}`)
})
await app.listen({ port: 5000 })