Authored by 陈峰

hbs callbak

... ... @@ -28,6 +28,7 @@ const _ = require('lodash');
const fp = require('lodash/fp');
const pkg = require('./package.json');
const hbsEvent = require('./config/hbsevent');
const app = express();
const helpers = global.yoho.helpers;
... ... @@ -75,7 +76,8 @@ app.use(global.yoho.hbs({
layoutsDir: path.join(__dirname, 'doraemon/views'),
partialsDir: path.join(__dirname, 'doraemon/views/partial'),
views: path.join(__dirname, 'doraemon/views'),
helpers: Object.assign(global.yoho.helpers, require('./utils/helpers'))
helpers: Object.assign(global.yoho.helpers, require('./utils/helpers')),
cb: hbsEvent.cb
}));
app.use(favicon(path.join(__dirname, '/favicon.ico')));
... ... @@ -181,4 +183,8 @@ try {
// listener
app.listen(config.port, function() {
logger.info('yohobuy start');
hbsEvent.event.on('hbs-complete', () => {
process.send && process.send('ready');
logger.info('hbs-all-complete');
});
});
... ...
... ... @@ -6,7 +6,8 @@
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -26,7 +27,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -3,7 +3,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -23,7 +24,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -24,7 +25,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -7,7 +7,8 @@
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -27,7 +28,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), path.join(__dirname, '../../mix')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./utils/helper'), global.yoho.helpers)
helpers: Object.assign(require('./utils/helper'), global.yoho.helpers),
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -6,7 +6,8 @@
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -26,7 +27,8 @@
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./helpers/pager'), require('./helpers/pager-seo'), global.yoho.helpers)
helpers: Object.assign(require('./helpers/pager'), require('./helpers/pager-seo'), global.yoho.helpers),
cb: hbsEvent.cb
}));
// require('./helpers/json');
... ...
... ... @@ -6,7 +6,8 @@
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -26,7 +27,8 @@
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./helper'), global.yoho.helpers)
helpers: Object.assign(require('./helper'), global.yoho.helpers),
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
const auth = require(`${global.middleware}/auth`);
... ... @@ -27,7 +28,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
require('./auth-config');
... ...
... ... @@ -6,7 +6,8 @@
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -26,7 +27,8 @@
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(global.yoho.helpers)
helpers: Object.assign(global.yoho.helpers),
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
'use strict';
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var passport = require('passport');
... ... @@ -27,7 +28,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./helper'), global.yoho.helpers)
helpers: Object.assign(require('./helper'), global.yoho.helpers),
cb: hbsEvent.cb
}));
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./helper'), global.yoho.helpers)
helpers: Object.assign(require('./helper'), global.yoho.helpers),
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -3,7 +3,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -23,7 +24,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
... ... @@ -5,7 +5,8 @@
*/
var express = require('express'),
path = require('path');
path = require('path'),
hbsEvent = require('../../config/hbsevent');
var app = express();
... ... @@ -25,7 +26,8 @@ app.use(global.yoho.hbs({
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
helpers: global.yoho.helpers,
cb: hbsEvent.cb
}));
// router
... ...
/**
* hbs预编译回调事件
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2017/08/14
*/
const EventEmitter = require('events');
const event = new EventEmitter();
let hbsEvent = {
cbTick: 0,
cbComTick: 0,
event
};
Object.defineProperty(hbsEvent, 'cb', {
get() {
hbsEvent.cbTick++;
return this._cb;
},
set(val) {
this._cb = val;
}
});
hbsEvent.cb = () => {
hbsEvent.cbComTick++;
if (hbsEvent.cbTick <= hbsEvent.cbComTick) {
event.emit('hbs-complete');
}
};
module.exports = hbsEvent;
... ...
... ... @@ -5,6 +5,7 @@
"script": "app.js",
"instances": "4",
"exec_mode": "cluster",
"wait_ready": true,
"merge_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm Z",
"error_file": "/Data/logs/node/yohobuy-node-err.log",
... ...