Authored by 姜枫

修改library

@@ -22,11 +22,14 @@ const memcached = require('connect-memcached'); @@ -22,11 +22,14 @@ const memcached = require('connect-memcached');
22 const hbs = require('express-handlebars'); 22 const hbs = require('express-handlebars');
23 const pkg = require('./package.json'); 23 const pkg = require('./package.json');
24 24
  25 +const yohoLib = require('yoho-node-lib');
  26 +
25 const app = express(); 27 const app = express();
26 const MemcachedStore = memcached(session); 28 const MemcachedStore = memcached(session);
27 29
28 -// 指定libray目录  
29 -global.library = path.resolve('./library'); 30 +// 全局注册library
  31 +yohoLib.global(config);
  32 +
30 global.middleware = path.resolve('./doraemon/middleware'); 33 global.middleware = path.resolve('./doraemon/middleware');
31 global.utils = path.resolve('./utils'); 34 global.utils = path.resolve('./utils');
32 35
@@ -41,7 +44,7 @@ app.engine('.hbs', hbs({ @@ -41,7 +44,7 @@ app.engine('.hbs', hbs({
41 defaultLayout: 'layout', 44 defaultLayout: 'layout',
42 layoutsDir: './doraemon/views', 45 layoutsDir: './doraemon/views',
43 partialsDir: './doraemon/views/partial', 46 partialsDir: './doraemon/views/partial',
44 - helpers: require(`${global.library}/helpers`) 47 + helpers: global.yoho.helpers
45 })); 48 }));
46 49
47 app.use(favicon(path.join(__dirname, '/public/favicon.ico'))); 50 app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
@@ -74,7 +77,7 @@ app.use((req, res, next) => { @@ -74,7 +77,7 @@ app.use((req, res, next) => {
74 next(); 77 next();
75 }); 78 });
76 79
77 -const logger = require('./library/logger'); 80 +const logger = global.yoho.logger;
78 81
79 // dispatcher 82 // dispatcher
80 try { 83 try {
@@ -23,7 +23,7 @@ app.engine('.hbs', hbs({ @@ -23,7 +23,7 @@ app.engine('.hbs', hbs({
23 defaultLayout: 'layout', 23 defaultLayout: 'layout',
24 layoutsDir: doraemon, 24 layoutsDir: doraemon,
25 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`], 25 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
26 - helpers: require('../../library/helpers') 26 + helpers: global.yoho.helpers
27 })); 27 }));
28 28
29 // router 29 // router
@@ -5,12 +5,11 @@ @@ -5,12 +5,11 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -const ServiceAPI = require(`${global.library}/api`).ServiceAPI;  
9 -const sign = require(`${global.library}/sign`);  
10 -const logger = require(`${global.library}/logger`); 8 +const sign = global.yoho.sign;
  9 +const logger = global.yoho.logger;
11 const headerModel = require('../../../doraemon/models/header'); 10 const headerModel = require('../../../doraemon/models/header');
12 11
13 -var api = new ServiceAPI(); 12 +var api = global.yoho.ServiceAPI;
14 13
15 const getstaticFile = (id) => { 14 const getstaticFile = (id) => {
16 return api.get('staticFileManage/queryById', sign.apiSign({ 15 return api.get('staticFileManage/queryById', sign.apiSign({
@@ -26,7 +26,7 @@ app.engine('.hbs', hbs({ @@ -26,7 +26,7 @@ app.engine('.hbs', hbs({
26 defaultLayout: 'layout', 26 defaultLayout: 'layout',
27 layoutsDir: doraemon, 27 layoutsDir: doraemon,
28 partialsDir: [`${partials}/partials`, `${doraemon}/partial`], 28 partialsDir: [`${partials}/partials`, `${doraemon}/partial`],
29 - helpers: require('../../library/helpers') 29 + helpers: global.yoho.helpers
30 })); 30 }));
31 31
32 32
@@ -9,18 +9,16 @@ const _ = require('lodash'); @@ -9,18 +9,16 @@ const _ = require('lodash');
9 9
10 const dataMap = require('../../../config/data-map'); 10 const dataMap = require('../../../config/data-map');
11 11
12 -const ServiceAPI = require(`${global.library}/api`).ServiceAPI;  
13 -const SearchAPI = require(`${global.library}/api`).SearchAPI;  
14 -const sign = require(`${global.library}/sign`);  
15 -const helpers = require(`${global.library}/helpers`); 12 +const sign = global.yoho.sign;
  13 +const helpers = global.yoho.helpers;
16 const images = require(`${global.utils}/images`); 14 const images = require(`${global.utils}/images`);
17 15
18 // const processProduct = require(`${global.utils}/product-process`).processProductList; 16 // const processProduct = require(`${global.utils}/product-process`).processProductList;
19 -const log = require(`${global.library}/logger`); 17 +const log = global.yoho.logger;
20 18
21 19
22 -const serviceApi = new ServiceAPI();  
23 -const searchApi = new SearchAPI(); 20 +const serviceApi = global.yoho.ServiceAPI;
  21 +const searchApi = global.yoho.SearchAPI;
24 22
25 const headerModel = require('../../../doraemon/models/header'); 23 const headerModel = require('../../../doraemon/models/header');
26 24
@@ -5,13 +5,12 @@ @@ -5,13 +5,12 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -const library = '../../../library';  
9 const passport = require('passport'); 8 const passport = require('passport');
10 const uuid = require('uuid'); 9 const uuid = require('uuid');
11 -const cookie = require(`${library}/cookie`);  
12 -const helpers = require(`${library}/helpers`);  
13 -const log = require(`${library}/logger`);  
14 -const config = require('../../../config/common'); 10 +const cookie = global.yoho.cookie;
  11 +const helpers = global.yoho.helpers;
  12 +const log = global.yoho.logger;
  13 +const config = global.yoho.config;
15 const AuthHelper = require('../models/auth-helper'); 14 const AuthHelper = require('../models/auth-helper');
16 15
17 const loginPage = `${config.siteUrl}/passport/login/index`; 16 const loginPage = `${config.siteUrl}/passport/login/index`;
@@ -26,7 +26,7 @@ app.engine('.hbs', hbs({ @@ -26,7 +26,7 @@ app.engine('.hbs', hbs({
26 defaultLayout: 'layout', 26 defaultLayout: 'layout',
27 layoutsDir: doraemon, 27 layoutsDir: doraemon,
28 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`], 28 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
29 - helpers: require(`${global.library}/helpers`) 29 + helpers: global.yoho.helpers
30 })); 30 }));
31 31
32 32
1 'use strict'; 1 'use strict';
2 2
3 -const library = '../../../library';  
4 -const API = require(`${library}/api`).API;  
5 -const sign = require(`${library}/sign`);  
6 -const api = new API(); 3 +const sign = global.yoho.sign;
  4 +const api = global.yoho.API;
7 5
8 class Auth { 6 class Auth {
9 7
@@ -24,7 +24,7 @@ app.engine('.hbs', hbs({ @@ -24,7 +24,7 @@ app.engine('.hbs', hbs({
24 defaultLayout: 'layout', 24 defaultLayout: 'layout',
25 layoutsDir: doraemon, 25 layoutsDir: doraemon,
26 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`], 26 partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
27 - helpers: require('../../library/helpers') 27 + helpers: global.yoho.helpers
28 })); 28 }));
29 29
30 // router 30 // router
@@ -6,10 +6,8 @@ @@ -6,10 +6,8 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 const utils = '../../../utils'; 9 const utils = '../../../utils';
11 -const API = require(`${library}/api`).API;  
12 -const api = new API(); 10 +const api = global.yoho.API;
13 const saleApi = require('./sale-api'); 11 const saleApi = require('./sale-api');
14 const outletsApi = require('./outlets-api'); 12 const outletsApi = require('./outlets-api');
15 const productProcess = require(`${utils}/product-process`); 13 const productProcess = require(`${utils}/product-process`);
@@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 -const API = require(`${library}/api`).API;  
11 -const ServiceAPI = require(`${global.library}/api`).ServiceAPI;  
12 -const serviceApi = new ServiceAPI();  
13 -const api = new API();  
14 -const sign = require(`${library}/sign`); 9 +
  10 +const serviceApi = global.yoho.ServiceAPI;
  11 +const api = global.yoho.API;
  12 +const sign = global.yoho.sign;
15 const _ = require('lodash'); 13 const _ = require('lodash');
16 14
17 const yhChannel = { 15 const yhChannel = {
@@ -5,9 +5,8 @@ @@ -5,9 +5,8 @@
5 * @Last Modified time: 2016-06-08 19:31:52 5 * @Last Modified time: 2016-06-08 19:31:52
6 */ 6 */
7 'use strict'; 7 'use strict';
8 -const library = '../../../library';  
9 const utils = '../../../utils'; 8 const utils = '../../../utils';
10 -const helpers = require(`${library}/helpers`); 9 +const helpers = global.yoho.helpers;
11 const _ = require('lodash'); 10 const _ = require('lodash');
12 const camelCase = require('../../../library/camel-case'); 11 const camelCase = require('../../../library/camel-case');
13 const productProcess = require(`${utils}/product-process`); 12 const productProcess = require(`${utils}/product-process`);
@@ -6,10 +6,8 @@ @@ -6,10 +6,8 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 const utils = '../../../utils'; 9 const utils = '../../../utils';
11 -const API = require(`${library}/api`).API;  
12 -const api = new API(); 10 +const api = global.yoho.API;
13 const list = require('./list'); 11 const list = require('./list');
14 const outletsProcess = require('./outlets-handler'); 12 const outletsProcess = require('./outlets-handler');
15 const outletsApi = require('./outlets-api'); 13 const outletsApi = require('./outlets-api');
@@ -18,7 +16,7 @@ const headerModel = require('../../../doraemon/models/header'); @@ -18,7 +16,7 @@ const headerModel = require('../../../doraemon/models/header');
18 const _ = require('lodash'); 16 const _ = require('lodash');
19 17
20 const publicHandler = require('./public-handler'); 18 const publicHandler = require('./public-handler');
21 -const log = require(`${global.library}/logger`); 19 +const log = global.yoho.logger;
22 20
23 // 奥莱频道资源码 21 // 奥莱频道资源码
24 const channelCode = { 22 const channelCode = {
@@ -7,8 +7,7 @@ @@ -7,8 +7,7 @@
7 7
8 'use strict'; 8 'use strict';
9 const _ = require('lodash'); 9 const _ = require('lodash');
10 -const library = '../../../library';  
11 -const helpers = require(`${library}/helpers`); 10 +const helpers = global.yoho.helpers;
12 const queryString = require('querystring'); 11 const queryString = require('querystring');
13 12
14 /** 13 /**
@@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 -const API = require(`${library}/api`).API;  
11 -const ServiceAPI = require(`${library}/api`).ServiceAPI;  
12 -const api = new API();  
13 -const serviceAPI = new ServiceAPI();  
14 -const sign = require(`${library}/sign`); 9 +
  10 +const serviceAPI = global.yoho.ServiceAPI;
  11 +const api = global.yoho.API;
  12 +const sign = global.yoho.sign;
15 const _ = require('lodash'); 13 const _ = require('lodash');
16 14
17 const yhChannel = { 15 const yhChannel = {
@@ -6,8 +6,7 @@ @@ -6,8 +6,7 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 -const helpers = require(`${library}/helpers`); 9 +const helpers = global.yoho.helpers;
11 const _ = require('lodash'); 10 const _ = require('lodash');
12 const anHour = 3600000; 11 const anHour = 3600000;
13 const aDay = anHour * 24; 12 const aDay = anHour * 24;
@@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -const library = '../../../library';  
10 const utils = '../../../utils'; 9 const utils = '../../../utils';
11 -const logger = require(`${library}/logger`);  
12 -const camelCase = require(`${library}/camel-case`);  
13 -const API = require(`${library}/api`).API;  
14 -const api = new API(); 10 +const logger = global.yoho.logger;
  11 +const camelCase = global.yoho.camelCase;
  12 +const api = global.yoho.API;
15 const saleApi = require('./sale-api'); 13 const saleApi = require('./sale-api');
16 const publicHandler = require('./public-handler'); 14 const publicHandler = require('./public-handler');
17 const saleHandler = require('./sale-handler'); 15 const saleHandler = require('./sale-handler');
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * @return {[type]} 3 * @return {[type]}
4 */ 4 */
5 const headerModel = require('../models/header'); 5 const headerModel = require('../models/header');
6 -const logger = require('../../library/logger'); 6 +const logger = global.yoho.logger;
7 7
8 exports.notFound = () => { 8 exports.notFound = () => {
9 return (req, res, next) => { 9 return (req, res, next) => {
1 const _ = require('lodash'); 1 const _ = require('lodash');
2 -const cookie = require('../../library/cookie'); 2 +const cookie = global.yoho.cookie;
3 3
4 module.exports = () => { 4 module.exports = () => {
5 return (req, res, next) => { 5 return (req, res, next) => {
@@ -8,12 +8,11 @@ @@ -8,12 +8,11 @@
8 8
9 const _ = require('lodash'); 9 const _ = require('lodash');
10 10
11 -const ServiceAPI = require(`${global.library}/api`).ServiceAPI;  
12 -const sign = require(`${global.library}/sign`); 11 +const sign = global.yoho.sign;
13 12
14 -const serviceApi = new ServiceAPI(); 13 +const serviceApi = global.yoho.ServiceAPI;
15 14
16 -const log = require(`${global.library}/logger`); 15 +const log = global.yoho.logger;
17 16
18 /** 17 /**
19 * 获取菜单 18 * 获取菜单
@@ -51,7 +51,8 @@ @@ -51,7 +51,8 @@
51 "serve-favicon": "^2.3.0", 51 "serve-favicon": "^2.3.0",
52 "uuid": "^2.0.2", 52 "uuid": "^2.0.2",
53 "winston": "^2.2.0", 53 "winston": "^2.2.0",
54 - "winston-daily-rotate-file": "^1.1.4" 54 + "winston-daily-rotate-file": "^1.1.4",
  55 + "yoho-node-lib": "0.0.4"
55 }, 56 },
56 "devDependencies": { 57 "devDependencies": {
57 "autoprefixer": "^6.3.6", 58 "autoprefixer": "^6.3.6",
1 'use strict'; 1 'use strict';
2 const _ = require('lodash'); 2 const _ = require('lodash');
3 -const camelCase = require('../library/camel-case');  
4 -const helpers = require('../library/helpers'); 3 +const camelCase = global.yoho.camelCase;
  4 +const helpers = global.yoho.helpers;
5 5
6 /** 6 /**
7 * 根据性别来决定 默认图片获取字段 如果是 2、3 7 * 根据性别来决定 默认图片获取字段 如果是 2、3
1 const _ = require('lodash'); 1 const _ = require('lodash');
2 -const camelCase = require('../library/camel-case'); 2 +const camelCase = global.yoho.camelCase;
3 3
4 /** 4 /**
5 * 处理楼层数据 5 * 处理楼层数据