-
Notifications
You must be signed in to change notification settings - Fork 32
/
edp-webserver-config.js
121 lines (105 loc) · 2.82 KB
/
edp-webserver-config.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
exports.port = 8848;
exports.directoryIndexes = true;
exports.documentRoot = __dirname;
var path = require('path');
var etpl = require('etpl');
var marked = require('marked');
var controls = require('./package.json').controls;
var highlight = require('highlight.js');
highlight.configure({
classPrefix: ''
});
var renderer = new marked.Renderer();
renderer.code = function (code, language) {
var style = 'display:' + (language === 'js' ? 'block' : 'none');
return ''
+ '<pre style="' + style + '"><code class="lang lang-' + language + '">'
+ highlight.highlightAuto(code).value
+ '</code></pre>';
};
marked.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
etpl.addFilter('markdown', function (source) {
return '<div class="markdown">' + marked(source) + '</div>';
});
etpl.addFilter('lower', function (source) {
return source.toLowerCase();
});
etpl.config({
namingConflict: 'override',
commandOpen: '{%',
commandClose: '%}'
});
etpl.compile(require('fs').readFileSync('./example/tpl/base.tpl', 'utf-8'));
exports.getLocations = function () {
return [
{
location: /\/$/,
handler: home( 'index.html' )
},
{
location: /\.css($|\?)/,
handler: [
autocss()
]
},
// smarty的配置
{
location: /^\/example\/smarty\/index\.php$/,
handler: [
php('php-cgi', '')
]
},
// etpl的配置
{
location: /\.tpl($|\?)/,
handler: [
file(),
function (context) {
console.log(112321);
var name = path.basename(context.request.pathname, '.tpl');
var data = context.content.toString('utf-8');
var renderer = etpl.compile(data);
var html = renderer({
controls: controls,
name: name
});
context.header['content-type'] = 'text/html';
context.content = html;
}
]
},
{
location: /\.less($|\?)/,
handler: [
file(),
less({
paths: [
__dirname,
__dirname + '/dep'
]
})
]
},
{
location: /^.*$/,
handler: [
file(),
proxyNoneExists()
]
}
];
};
exports.injectResource = function ( res ) {
for ( var key in res ) {
global[ key ] = res[ key ];
}
};