-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (48 loc) · 1.64 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
57
58
var express = require('express'),
app = express(),
swig = require('swig'),
router = require(__dirname + '/config/routes')(express),
stylus = require('stylus'),
Vow = require('vow'),
VM = require('vm'),
fs = require('fs'),
server;
//register template engine
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/templates');
app.set('staticPath', '/static');
app.use(router);
app.use('/css', function(req, res, next){
var fs = require('fs'),
stylPath = req.originalUrl.replace(/(\d{1,}|\w{1,}|_{1,})\.css$/i, '$1' + '.styl'), data;
data = fs.readFileSync(__dirname + app.get('staticPath') + stylPath, { encoding: 'utf8' }, function(err, data){
if (err) throw err;
});
stylus(data).render(function(err, css){
if (err) throw err;
fs.writeFileSync(__dirname + app.get('staticPath') + req.originalUrl, css);
});
next();
})
app.get('/test', function(req, res){
var BEMHTML = require('./desktop.bundles/index/index.bemhtml.js').BEMHTML,
bemtree = fs.readFileSync('./desktop.bundles/index/index.bemtree.js', 'utf-8');
var context = VM.createContext({
console: console,
Vow: Vow
})
VM.runInContext(bemtree, context);
BEMTREE = context.BEMTREE;
BEMTREE.apply({
block: 'b-header',
data: { mod: 'tryhard' }
}).then(function(json){
console.log(json.content[0].content);
})
});
//static url
app.use(express.static(__dirname + app.get('staticPath')));
server = app.listen(3000, function () {
console.log('Server is running at port ' + server.address().port);
})