Authored by htoooth

zookeeper

@@ -13,6 +13,8 @@ const bodyParser = require('body-parser'); @@ -13,6 +13,8 @@ const bodyParser = require('body-parser');
13 const cookieParser = require('cookie-parser'); 13 const cookieParser = require('cookie-parser');
14 const favicon = require('serve-favicon'); 14 const favicon = require('serve-favicon');
15 const session = require('yoho-express-session'); 15 const session = require('yoho-express-session');
  16 +const _ = require('lodash');
  17 +const fp = require('lodash/fp');
16 18
17 const memcached = require('connect-memcached'); 19 const memcached = require('connect-memcached');
18 const hbs = require('express-handlebars'); 20 const hbs = require('express-handlebars');
@@ -27,15 +29,24 @@ const MemcachedStore = memcached(session); @@ -27,15 +29,24 @@ const MemcachedStore = memcached(session);
27 // 全局注册library 29 // 全局注册library
28 yohoLib.global(config); 30 yohoLib.global(config);
29 31
  32 +const helpers = global.yoho.helpers;
  33 +
  34 +// NOTE: 这里修改了图片质量的参数
  35 +helpers.image = _.flow(helpers.image, fp.replace(/\/quality\/\d*$/, '/quality/90'));
  36 +helpers.json = JSON.stringify;
  37 +
30 global.middleware = path.resolve('./doraemon/middleware'); 38 global.middleware = path.resolve('./doraemon/middleware');
31 global.utils = path.resolve('./utils'); 39 global.utils = path.resolve('./utils');
32 40
33 // 向模板注入变量 41 // 向模板注入变量
34 app.locals.devEnv = app.get('env') === 'development'; 42 app.locals.devEnv = app.get('env') === 'development';
35 app.locals.version = pkg.version; 43 app.locals.version = pkg.version;
  44 +app.locals.__YOHO_CONFIG = {};
36 45
37 // zookeeper设置 46 // zookeeper设置
38 -require('yoho-zookeeper')(config.zookeeperServer, 'pc', app.locals); 47 +require('yoho-zookeeper')(config.zookeeperServer, 'pc', app.locals.__YOHO_CONFIG);
  48 +console.log(app.locals.__YOHO_CONFIG);
  49 +
39 50
40 app.set('subdomain offset', 2); 51 app.set('subdomain offset', 2);
41 app.set('view engine', '.hbs'); 52 app.set('view engine', '.hbs');
1 -<!DOCTYPE html>  
2 -<html>  
3 - <head>  
4 - <meta charset="utf-8">  
5 - <title>{{title}}</title>  
6 - <meta name="keywords" content="{{keywords}}">  
7 - <meta name="description" content="{{description}}">  
8 - <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">  
9 - <meta http-equiv="cleartype" content="on">  
10 - <meta name="apple-mobile-web-app-status-bar-style" content="black" />  
11 - <meta content="telephone=no" name="format-detection" />  
12 - <meta content="email=no" name="format-detection" />  
13 - <link rel="dns-prefetch" href="//cdn.yoho.cn">  
14 - <link rel="dns-prefetch" href="//static.yohobuy.com">  
15 - <link rel="dns-prefetch" href="//img12.static.yhbimg.com">  
16 - <link rel="dns-prefetch" href="//img13.static.yhbimg.com">  
17 - {{#if devEnv}}  
18 - <link rel="stylesheet" href="//localhost:5002/css/index.css">  
19 - {{^}}  
20 - <link rel="stylesheet" href="//cdn.yoho.cn/yohobuy-node/{{version}}/index.css">  
21 - {{/if}}  
22 - </head>  
23 - <body>  
24 - {{> header}}  
25 - {{> common/simple-header}}  
26 - {{#if pageErr}}  
27 - {{> 404}}  
28 - {{^}}  
29 - {{{body}}}  
30 - {{/if}}  
31 - {{> footer}}  
32 - {{#if devEnv}}  
33 - <script src="//localhost:5002/libs.js"></script>  
34 - <script src="//localhost:5002/{{module}}.{{page}}.js"></script>  
35 - {{^}}  
36 - <script src="//cdn.yoho.cn/yohobuy-node/{{version}}/libs.js"></script>  
37 - <script src="//cdn.yoho.cn/yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script>  
38 - {{> analysis}}  
39 - {{/if}}  
40 - </body>  
41 -</html> 1 +<!DOCTYPE html>
  2 +<html>
  3 + <head>
  4 + <meta charset="utf-8">
  5 + <title>{{title}}</title>
  6 + <meta name="keywords" content="{{keywords}}">
  7 + <meta name="description" content="{{description}}">
  8 + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  9 + <meta http-equiv="cleartype" content="on">
  10 + <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  11 + <meta content="telephone=no" name="format-detection" />
  12 + <meta content="email=no" name="format-detection" />
  13 + <link rel="dns-prefetch" href="//cdn.yoho.cn">
  14 + <link rel="dns-prefetch" href="//static.yohobuy.com">
  15 + <link rel="dns-prefetch" href="//img12.static.yhbimg.com">
  16 + <link rel="dns-prefetch" href="//img13.static.yhbimg.com">
  17 + {{#if devEnv}}
  18 + <link rel="stylesheet" href="//localhost:5002/css/index.css">
  19 + {{^}}
  20 + <link rel="stylesheet" href="//cdn.yoho.cn/yohobuy-node/{{version}}/index.css">
  21 + {{/if}}
  22 + </head>
  23 + <body>
  24 + {{> header}}
  25 + {{> common/simple-header}}
  26 + {{#if pageErr}}
  27 + {{> 404}}
  28 + {{^}}
  29 + {{{body}}}
  30 + {{/if}}
  31 + {{> footer}}
  32 +
  33 + <!--降级配置-->
  34 + <stript>
  35 + var __YOHO_CONFIG = {{{json __YOHO_CONFIG}}}
  36 + </stript>
  37 +
  38 + {{#if devEnv}}
  39 + <script src="//localhost:5002/libs.js"></script>
  40 + <script src="//localhost:5002/{{module}}.{{page}}.js"></script>
  41 + {{^}}
  42 + <script src="//cdn.yoho.cn/yohobuy-node/{{version}}/libs.js"></script>
  43 + <script src="//cdn.yoho.cn/yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script>
  44 + {{> analysis}}
  45 + {{/if}}
  46 + </body>
  47 +</html>
@@ -16,9 +16,6 @@ const itemFromBase = { @@ -16,9 +16,6 @@ const itemFromBase = {
16 saleSpecial: {domain: 'sale', module: 's'}// sale.yohobuy.com 16 saleSpecial: {domain: 'sale', module: 's'}// sale.yohobuy.com
17 }; 17 };
18 18
19 -// NOTE: 这里修改了图片质量的参数  
20 -helpers.image = _.flow(helpers.image, fp.replace(/\/quality\/\d*$/, '/quality/90'));  
21 -  
22 /** 19 /**
23 * 根据性别来决定 默认图片获取字段 如果是 2、3 20 * 根据性别来决定 默认图片获取字段 如果是 2、3
24 * 21 *