Authored by 姜枫

add new hbs render

... ... @@ -7,19 +7,23 @@
const config = require('./config/common');
global.Promise = require('bluebird');
const yohoLib = require('yoho-node-lib');
// 全局注册library
yohoLib.global(config);
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const yohoLib = require('yoho-node-lib');
const session = require('yoho-express-session');
const memcached = require('connect-memcached');
const hbs = require('express-handlebars');
const pkg = require('./package.json');
const session = require('cookie-session');
const app = express();
const MemcachedStore = memcached(session);
// 向模板注入变量
app.locals.devEnv = app.get('env') === 'development';
... ... @@ -28,22 +32,18 @@ app.locals.version = pkg.version;
// 访问域名层级
app.set('subdomain offset', 3);
// 全局注册library
yohoLib.global(config);
// 指定libray目录
global.utils = path.resolve('./utils');
const logger = global.yoho.logger;
app.set('subdomain offset', 3);
app.set('view engine', '.hbs');
app.set('views', './doraemon/views');
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: './doraemon/views',
partialsDir: './doraemon/views/partial',
layoutsDir: path.join(__dirname, 'doraemon/views'),
partialsDir: path.join(__dirname, 'doraemon/views/partial'),
views: path.join(__dirname, 'doraemon/views'),
helpers: global.yoho.helpers
}));
... ... @@ -56,22 +56,8 @@ app.use(bodyParser.urlencoded({
app.use(cookieParser());
app.use(session({
proxy: true,
resave: false,
saveUninitialized: true,
unset: 'destroy',
secret: '82dd7e724f2c6870472c89dfa43cf48d',
name: 'yohobuy_session',
cookie: {
domain: 'yohobuy.com',
httpOnly: false
},
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohobuy_session:',
timeout: 1000,
retries: 0
})
secret: '82dd7e724f2c6870472c89dfa43cf48d'
}));
app.use((req, res, next) => {
... ...
... ... @@ -6,7 +6,6 @@
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars'),
helpers = require(path.join(global.utils, 'helpers'));
var app = express();
... ... @@ -19,11 +18,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: Object.assign({}, global.yoho.helpers, helpers)
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, './views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, './views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, './views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, './views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
'use strict';
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var passport = require('passport');
... ... @@ -20,12 +19,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -6,8 +6,7 @@
'use strict';
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -19,12 +18,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -12,6 +12,7 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
app: 'h5',
appVersion: '4.9.2', // 调用api的版本
appName: 'm.yohobuy.com',
port: 6001,
siteUrl: '//m.yohobuy.com',
assetUrl: '//localhost:5001',
... ... @@ -36,6 +37,7 @@ module.exports = {
activity: '//activity.yohobuy.com',
index: '//m.yohobuy.com'
},
trace: true,
useCache: false,
memcache: {
master: ['192.168.102.168:12111'],
... ... @@ -64,7 +66,7 @@ module.exports = {
measurement: 'yohobuy_wap_node_log',
level: 'debug', // logger level
host: 'influxdblog.yohoops.org', // influxdb host
port: '4444' // influxdb port
port: 4444 // influxdb port
},
console: {
level: 'debug',
... ...
... ... @@ -21,15 +21,12 @@
"bluebird": "^3.4.6",
"body-parser": "^1.15.2",
"cheerio": "^0.22.0",
"connect-memcached": "^0.2.0",
"connect-multiparty": "^2.0.0",
"cookie-parser": "^1.4.3",
"cookie-session": "^1.2.0",
"express": "^4.14.0",
"express-handlebars": "^3.0.0",
"influxdb-winston": "^1.0.1",
"lodash": "^4.16.1",
"md5": "^2.1.0",
"memcached": "^2.2.1",
"moment": "^2.15.1",
"morgan": "^1.7.0",
"passport": "^0.3.2",
... ... @@ -41,10 +38,7 @@
"request-promise": "^3.0.0",
"serve-favicon": "^2.3.0",
"uuid": "^2.0.3",
"winston": "^2.2.0",
"yoho-express-session": "^1.14.1",
"winston-daily-rotate-file": "^1.3.0",
"yoho-node-lib": "0.0.49"
"yoho-node-lib": "0.1.8"
},
"devDependencies": {
"autoprefixer": "^6.3.7",
... ...