Authored by 毕凯

增强代码检查

1 -dist/  
2 -gulpfile.js  
3 -node_modules  
@@ -3,25 +3,23 @@ @@ -3,25 +3,23 @@
3 * @author xuqi<qi.xu@yoho.cn> 3 * @author xuqi<qi.xu@yoho.cn>
4 * @date: 2016/3/28 4 * @date: 2016/3/28
5 */ 5 */
6 -  
7 var express = require('express'), 6 var express = require('express'),
8 path = require('path'), 7 path = require('path'),
9 exphbs = require('express-handlebars'), 8 exphbs = require('express-handlebars'),
10 - bodyParser = require('body-parser');  
11 -  
12 -var morgan = require('morgan'), 9 + bodyParser = require('body-parser'),
  10 + morgan = require('morgan'),
13 favicon = require('serve-favicon'), 11 favicon = require('serve-favicon'),
14 cookieParser = require('cookie-parser'), 12 cookieParser = require('cookie-parser'),
15 session = require('express-session'), 13 session = require('express-session'),
16 connectRedis = require('connect-redis'), 14 connectRedis = require('connect-redis'),
17 cors = require('cors'); 15 cors = require('cors');
18 16
19 -var app = express(),  
20 - RedisStore = connectRedis(session);  
21 -  
22 var config = require('./config'); 17 var config = require('./config');
23 var sign = require('./library/sign'); 18 var sign = require('./library/sign');
24 19
  20 +var app = express(),
  21 + RedisStore = connectRedis(session);
  22 +
25 // 向模板注入变量 23 // 向模板注入变量
26 app.locals.devEnv = app.get('env') === 'development'; 24 app.locals.devEnv = app.get('env') === 'development';
27 app.locals.proEnv = app.get('env') === 'production'; 25 app.locals.proEnv = app.get('env') === 'production';
@@ -49,23 +49,28 @@ function makeSign(argument) { @@ -49,23 +49,28 @@ function makeSign(argument) {
49 49
50 // 生成API签名,调用后端接口的时候有私钥校验 50 // 生成API签名,调用后端接口的时候有私钥校验
51 exports.apiSign = function(params) { 51 exports.apiSign = function(params) {
  52 +
  53 + /* eslint-disable */
52 var sign = packageSort(Object.assign({ 54 var sign = packageSort(Object.assign({
53 - 'client_type': 'web',  
54 - 'private_key': privateKey.web,  
55 - 'app_version': '3.8.2',  
56 - 'os_version': 'yohobuy:h5',  
57 - 'screen_size': '720x1280',  
58 - 'v': '7' 55 + client_type: 'web',
  56 + private_key: privateKey.web,
  57 + app_version: '3.8.2',
  58 + os_version: 'yohobuy:h5',
  59 + screen_size: '720x1280',
  60 + v: '7'
59 }, params)); 61 }, params));
60 62
  63 + /* eslint-enable */
  64 +
61 return Object.assign(sign, { 65 return Object.assign(sign, {
62 - client_secret: makeSign(sign) 66 +
  67 + client_secret: makeSign(sign) // eslint-disable-line camelcase
63 }); 68 });
64 }; 69 };
65 70
66 // 检查签名,APP 访问 H5 页面的时候需要检查 71 // 检查签名,APP 访问 H5 页面的时候需要检查
67 exports.checkSign = function(params) { 72 exports.checkSign = function(params) {
68 - var clientSecret = params.client_secret, 73 + var clientSecret = params.client_secret, // eslint-disable-line camelcase
69 sortedParams; 74 sortedParams;
70 75
71 // 忽略部分参数 76 // 忽略部分参数
@@ -74,7 +79,7 @@ exports.checkSign = function(params) { @@ -74,7 +79,7 @@ exports.checkSign = function(params) {
74 delete params.debug_data; 79 delete params.debug_data;
75 delete params['/api']; 80 delete params['/api'];
76 81
77 - params.private_key = privateKey[params.client_type]; 82 + params.private_key = privateKey[params.client_type]; // eslint-disable-line camelcase
78 sortedParams = packageSort(params); 83 sortedParams = packageSort(params);
79 84
80 return clientSecret === makeSign(sortedParams); 85 return clientSecret === makeSign(sortedParams);
@@ -82,7 +87,7 @@ exports.checkSign = function(params) { @@ -82,7 +87,7 @@ exports.checkSign = function(params) {
82 87
83 // 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式 88 // 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式
84 exports.webSign = function(params) { 89 exports.webSign = function(params) {
85 - var privateKey = 'yohobuyapp'; 90 + var webPrivateKey = 'yohobuyapp';
86 91
87 - return params.key === md5(md5(privateKey) + params.uid); 92 + return params.key === md5(md5(webPrivateKey) + params.uid);
88 }; 93 };
@@ -12,7 +12,10 @@ module.exports = (req, res, next) => { @@ -12,7 +12,10 @@ module.exports = (req, res, next) => {
12 12
13 if (req.isApp && !req.query.uid) { 13 if (req.isApp && !req.query.uid) {
14 referrer = referrer.split('?')[0]; 14 referrer = referrer.split('?')[0];
  15 +
  16 + /*eslint-disable */
15 loginUrl += '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + referrer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'; 17 loginUrl += '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + referrer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
  18 + /*eslint-enable */
16 19
17 return res.redirect(loginUrl); // 跳转APP登录页 20 return res.redirect(loginUrl); // 跳转APP登录页
18 } else if (!req.isApp && !req.cookies._UID) { 21 } else if (!req.isApp && !req.cookies._UID) {
@@ -11,9 +11,9 @@ exports.sendSingleMessage = (data) => { @@ -11,9 +11,9 @@ exports.sendSingleMessage = (data) => {
11 var defaultParam = { 11 var defaultParam = {
12 method: 'web.inbox.setSingleMessage', 12 method: 'web.inbox.setSingleMessage',
13 type: 1, 13 type: 1,
14 - verify_key: '',  
15 - send_uid: 0,  
16 - callback: '' 14 + verify_key: '', // eslint-disable-line camelcase
  15 + send_uid: 0, // eslint-disable-line camelcase
  16 + callback: '' // eslint-disable-line camelcase
17 }; 17 };
18 18
19 return api.post('/', Object.assign(defaultParam, data)); // 所有数据返回一个 Promise,方便 Promise.all 调用 19 return api.post('/', Object.assign(defaultParam, data)); // 所有数据返回一个 Promise,方便 Promise.all 调用
@@ -31,8 +31,8 @@ module.exports = { @@ -31,8 +31,8 @@ module.exports = {
31 }) 31 })
32 ], 32 ],
33 babel: { 33 babel: {
34 - presets: ['es2015'],  
35 - plugins: ['transform-runtime'] 34 + presets: [ 'es2015' ],
  35 + plugins: [ 'transform-runtime' ]
36 } 36 }
37 }; 37 };
38 if (process.env.NODE_ENV === 'production') { 38 if (process.env.NODE_ENV === 'production') {
@@ -31,8 +31,8 @@ module.exports = { @@ -31,8 +31,8 @@ module.exports = {
31 }) 31 })
32 ], 32 ],
33 babel: { 33 babel: {
34 - presets: ['es2015'],  
35 - plugins: ['transform-runtime'] 34 + presets: [ 'es2015' ],
  35 + plugins: [ 'transform-runtime' ]
36 } 36 }
37 }; 37 };
38 if (process.env.NODE_ENV === 'production') { 38 if (process.env.NODE_ENV === 'production') {
@@ -31,8 +31,8 @@ module.exports = { @@ -31,8 +31,8 @@ module.exports = {
31 }) 31 })
32 ], 32 ],
33 babel: { 33 babel: {
34 - presets: ['es2015'],  
35 - plugins: ['transform-runtime'] 34 + presets: [ 'es2015' ],
  35 + plugins: [ 'transform-runtime' ]
36 } 36 }
37 }; 37 };
38 if (process.env.NODE_ENV === 'production') { 38 if (process.env.NODE_ENV === 'production') {
@@ -31,8 +31,8 @@ module.exports = { @@ -31,8 +31,8 @@ module.exports = {
31 }) 31 })
32 ], 32 ],
33 babel: { 33 babel: {
34 - presets: ['es2015'],  
35 - plugins: ['transform-runtime'] 34 + presets: [ 'es2015' ],
  35 + plugins: [ 'transform-runtime' ]
36 } 36 }
37 }; 37 };
38 if (process.env.NODE_ENV === 'production') { 38 if (process.env.NODE_ENV === 'production') {
@@ -2,7 +2,7 @@ var querystring = require('querystring'); @@ -2,7 +2,7 @@ var querystring = require('querystring');
2 2
3 var config = require('../config'); 3 var config = require('../config');
4 4
5 -function url(uri, param, module) { 5 +function urlFormat(uri, param, module) {
6 var url = '', 6 var url = '',
7 SUB_DOMAIN = '.m.yohobuy.com'; 7 SUB_DOMAIN = '.m.yohobuy.com';
8 8
@@ -41,4 +41,4 @@ function url(uri, param, module) { @@ -41,4 +41,4 @@ function url(uri, param, module) {
41 return url; 41 return url;
42 } 42 }
43 43
44 -module.exports = url; 44 +module.exports = urlFormat;