-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.js
57 lines (37 loc) · 1.25 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Koa from 'koa'
const views = require('koa-views');
const avalon = require('./dist/avalon2.2');
const fs = require('fs');
const path = require('path');
import convert from 'koa-convert'
const minify = require('html-minifier').minify;
import koaStaticPlus from 'koa-static-plus'
const app = new Koa()
app.use(koaStaticPlus(path.join(__dirname, '/dist'), {
pathPrefix: ''
}))
//当前页面VM
var vm = require('./src/vm')
//当前页面模板
var page = fs.readFileSync('./src/aaa.html', 'utf-8');
//渲染器
var serveRender = require('./dist/serverRender2.2')
var obj = serveRender(vm, page)
for(var i in obj.templates){
obj.templates[i] = minify(obj.templates[i],{
collapseInlineTagWhitespace: true,
collapseWhitespace:true
})
}
var files = JSON.stringify(obj.templates)
var header = '<!document html><html><head>'+
'<script src="./avalon2.2.js"><\/script>'+
'<script src="./vm.js"><\/script>'+
'<script> avalon.serverTemplates= ' + files + '<\/script>' +
'</head><body>'
var footer = '</body></html>'
app.use(async function(ctx){
await (ctx.body = (header+ obj.html+ footer))
})
app.listen(3000, () => console.log('server started 3000'))
export default app