-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathindex.js
40 lines (33 loc) · 868 Bytes
/
index.js
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
const Koa = require('koa')
const app = new Koa()
const {readFileSync} = require('fs')
const {template} = require('lodash')
const {renderAsyncFragments} = require('@riotjs/ssr')
const unregister = require('@riotjs/register')()
const page = readFileSync('./index.html', 'utf8')
const pages = [{
path: '/',
label: 'Home',
component: 'home'
}, {
path: '/about',
label: 'About',
component: 'about'
}]
app.use(require('koa-static')('./public'))
app.use(async ctx => {
const initialState = {
initialRoute: ctx.request.url,
pages,
}
const App = require('./app/app.riot').default
const {html, css} = await renderAsyncFragments('app', App, initialState)
ctx.body = template(page)({
html,
initialState: JSON.stringify(initialState),
css
})
unregister()
})
app.listen(3000)
console.log('App running on: http://localhost:3000')