forked from bem/project-stub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
58 lines (46 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');
var ExpressBem = require('express-bem');
// create app and bem
var app = Express();
var bem = ExpressBem({
projectRoot: './', // bem project root, used for bem make only
path: './desktop.bundles' // path to your bundles
});
// here to lookup bundles at your path you need small patch
app.bem = bem.bindTo(app);
if (process.env.NODE_ENV !== 'production') {
bem.usePlugin(process.env.EXPRESS_BEM_MAKER === 'enb' ? 'express-bem-enb-make' : 'express-bem-tools-make',
{verbosity: 'debug'});
}
// register engines
bem.usePlugin('express-bem-bemtree'); // requires module express-bem-bemtree
bem.usePlugin('express-bem-bemhtml'); // ... express-bem-bemhtml
bem.engine('fullstack', '.bem', ['.bemhtml.js', '.bemtree.js'], function (name, options, cb) {
var view = this;
// pass options.bemjson directly to bemhtml
if (options.bemjson) return view.thru('bemhtml');
// return bemjson if requested
if (options.raw === true) return view.thru('bemtree');
// full stack
view.thru('bemtree', name, options, function (err, bemjson) {
if (err) return cb(err);
options.bemjson = bemjson;
view.thru('bemhtml', name, options, function (err, data) {
if (err) return cb(err);
cb(null, data);
});
});
});
// set default engine extension
app.set('view engine', '.bem');
// routes
app.get('/', function (req, res) {
res.render('index', {
block : 'page',
content : 'asdasd'
});
});
var server = app.listen(process.env.NODE_PORT || process.env.PORT || 3000, function () {
var listenOn = server.address();
console.log('Server listen on ' + listenOn.address + ':' + listenOn.port);
});