-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdeno.dev.tsx
68 lines (56 loc) · 1.4 KB
/
deno.dev.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
57
58
59
60
61
62
63
64
65
66
67
68
import { h, Helmet, renderSSR, Component } from './deno_lib/mod.ts'
import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts'
const comments = ['Comment One', 'Comment Two']
class Comments extends Component {
render() {
return (
<ul>
{this.props.comments.map((comment: any) => {
return <li>{comment}</li>
})}
</ul>
)
}
}
const App = () => (
<div>
<Helmet>
<title>Nano JSX SSR</title>
<meta name="description" content="Server Side Rendered Nano JSX Application" />
</Helmet>
<Helmet footer>
<script src="/bundle.js"></script>
</Helmet>
<h2>Comments</h2>
<div id="comments">
<Comments comments={comments} />
</div>
</div>
)
const ssr = renderSSR(<App />)
const { body, head, footer } = Helmet.SSR(ssr)
console.log(body)
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 })