Authored by ccbikai

Merge branch 'develop' into feature/sale

... ... @@ -17,8 +17,10 @@ const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const session = require('express-session');
const memcached = require('connect-memcached');
const session = require('yoho-express-session');
const memcached = require('yoho-connect-memcached');
const uuid = require('uuid');
const _ = require('lodash');
const pkg = require('./package.json');
const app = express();
... ... @@ -40,17 +42,35 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
secret: '3e5fec7deca0b8305cefe2ad9d90ff5e',
name: 'PHPSESSID',
prefix: 'yohobuy',
proxy: true,
resave: true,
resave: false,
saveUninitialized: true,
unset: 'destroy',
secret: 'nothing', // 兼容 PHP SESSION,sessionID 不加密
name: 'PHPSESSID', // 兼容 PHP SESSION
genid: () => {
return uuid.v4(); // 兼容 PHP SESSION
},
cookie: {
domain: 'yohobuy.com'
},
store: new MemcachedStore({
hosts: config.memcache.session
hosts: config.memcache.session,
prefix: 'qinsessionsession:', // 兼容 PHP SESSION
key: 'yohobuy_session' // 兼容 PHP SESSION
})
}));
app.use((req, res, next) => {
req.user = {};
// 从 PHP 写的 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
req.user.uid = req.session._LOGIN_UID;
}
next();
});
// dispatcher
require('./dispatch')(app);
... ...
... ... @@ -9,7 +9,6 @@ const _ = require('lodash');
const channelModel = require('../models/channel');
const helpers = require(`${library}/helpers`);
const log = require(`${library}/logger`);
const cookie = require(`${library}/cookie`);
const renderData = {
module: 'channel',
... ... @@ -43,7 +42,7 @@ const channelLogger = (err, res) => {
const channelPage = (req, res, data) => {
channelModel.getChannelDate({
gender: data.gender,
uid: cookie.getUid(req)
uid: req.user.uid
}).then(result => {
res.render('channel', Object.assign(renderData, data, result));
}).catch((err) => {
... ...
... ... @@ -52,11 +52,13 @@ module.exports = {
if (isProduction) {
Object.assign(module.exports, {
appName: 'm.yohobuy.com',
useOneapm: true
useOneapm: true,
useCache: true
});
} else if (isTest) {
Object.assign(module.exports, {
appName: 'm.yohobuy.com for test',
useOneapm: true
useOneapm: true,
useCache: true
});
}
... ...
... ... @@ -123,8 +123,6 @@ class Http {
timeout: 3000
};
// console.log('in api : ' + config.useCache);
// 从缓存获取数据
if (config.useCache && cacheOption) {
return this._requestFromCache(options);
... ...
... ... @@ -11,11 +11,12 @@
"start": "node app.js",
"dev": "node_modules/.bin/nodemon -e js,hbs -i public/ app.js",
"online": "NODE_ENV=\"production\" node app.js",
"debug": "DEBUG=\"express:*\" node app.js",
"debug": "DEBUG=\"express:*\" node_modules/.bin/nodemon -e js,hbs -i public/ app.js",
"lint-js": "./node_modules/.bin/eslint -c .eslintrc --cache --fix .",
"lint-css": "./node_modules/.bin/stylelint --config .stylelintrc public/scss/**/*.css",
"precommit": "node lint.js",
"test": "./node_modules/.bin/nyc ./node_modules/.bin/ava"
"test": "NODE_ENV=test ./node_modules/.bin/nyc ./node_modules/.bin/ava",
"posttest": "./node_modules/.bin/nyc report --reporter=html"
},
"ava": {
"tap": true,
... ... @@ -30,13 +31,11 @@
},
"license": "MIT",
"dependencies": {
"bluebird": "^3.3.5",
"bluebird": "^3.4.0",
"body-parser": "^1.15.0",
"connect-memcached": "^0.2.0",
"cookie-parser": "^1.4.1",
"express": "^4.13.1",
"express-handlebars": "^3.0.0",
"express-session": "^1.13.0",
"influxdb-winston": "^1.0.1",
"lodash": "^4.12.0",
"md5": "^2.1.0",
... ... @@ -46,15 +45,17 @@
"oneapm": "^1.2.20",
"request-promise": "^3.0.0",
"serve-favicon": "^2.3.0",
"uuid": "^2.0.2",
"winston": "^2.2.0",
"winston-daily-rotate-file": "^1.0.1"
"winston-daily-rotate-file": "^1.0.1",
"yoho-connect-memcached": "^1.0.3",
"yoho-express-session": "^1.0.2"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
"ava": "^0.14.0",
"babel-cli": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"eslint": "^2.10.2",
"eslint-config-yoho": "^1.0.1",
"gulp": "^3.9.1",
... ... @@ -64,7 +65,6 @@
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-util": "^3.0.7",
"husky": "^0.11.4",
"mocha": "^2.4.5",
"nodemon": "1.9.2",
"nyc": "^6.4.3",
"postcss-assets": "^4.0.1",
... ... @@ -82,7 +82,7 @@
"precss": "^1.4.0",
"rewire": "^2.5.1",
"shelljs": "^0.7.0",
"stylelint": "^6.3.3",
"stylelint": "^6.4.1",
"stylelint-config-yoho": "^1.2.3",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
... ...
.yoho-footer {
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 640px;
font-size: 24px;
background-color: #fff;
position: relative;
... ...
... ... @@ -7,14 +7,8 @@
'use strict';
const test = require('ava');
// const rewire = require('rewire');
// const shelljs = require('shelljs');
const sign = require('../../library/sign');
// let config = rewire('../../config/common');
const API = require('../../library/api').API;
const ServiceAPI = require('../../library/api').ServiceAPI;
... ... @@ -22,17 +16,6 @@ const SearchAPI = require('../../library/api').SearchAPI;
const getUrl = 'operations/api/v6/category/getCategory';
// test.before('create log folder', (t) => {
// shelljs.mkdir('log');
// t.pass();
// });
//
// test.after('delete log folder', (t) => {
// shelljs.rm('-rf', 'log');
// t.pass();
// });
test('api constructor test', (t) => {
let api = new ServiceAPI();
let api2 = new API();
... ... @@ -103,5 +86,3 @@ test('api multiple fail call test', (t) => {
}
});
});
... ...
... ... @@ -40,7 +40,6 @@ test('cache get test', (t) => {
test('cache get multi test', (t) => {
cache.set(anotherKey, anotherValue);
return cache.getMulti([testKey, anotherKey]).then((values) => {
console.log(values);
t.is(values[testKey], testValue);
t.is(values[anotherKey], JSON.stringify(anotherValue));
});
... ... @@ -68,3 +67,45 @@ test('cache set to slave', (t) => {
cache.del(slaveTestKey);
});
});
test('cache get test, key is not a string', (t) => {
return cache.get(123).then((v) => {
t.notOk(v);
});
});
test('cache get multi test, key is not an array', (t) => {
return cache.getMulti(123).then((v) => {
t.notOk(v);
});
});
test('cache get from slave test, key is not a string', (t) => {
return cache.getFromSlave(123).then((v) => {
t.notOk(v);
});
});
test('cache get multi from slave test, key is not an array', (t) => {
return cache.getMultiFromSlave(123).then((v) => {
t.notOk(v);
});
});
test('cache set test, key is not a string', (t) => {
return cache.set(123).then((v) => {
t.notOk(v);
});
});
test('cache set multi test, key is not an array', (t) => {
return cache.setSlave(123).then((v) => {
t.notOk(v);
});
});
test('cache del test, key is not a string', (t) => {
return cache.del(123).then((v) => {
t.notOk(v);
});
});
... ...
... ... @@ -3,45 +3,16 @@
*/
const test = require('ava');
const shelljs = require('shelljs');
const logger = require('../../library/logger');
const today = () => {
let now = new Date();
let s = now.getFullYear();
if (now.getMonth() < 10) {
s += '-0' + now.getMonth();
} else {
s += now.getMonth();
}
if (now.getDay() < 10) {
s += '-0' + now.getDay();
} else {
s += now.getDay();
}
return s;
};
// test.before('create log folder', t => {
// shelljs.mkdir('log');
// t.pass();
// });
//
// test.after('clean test log file ', t => {
// shelljs.rm('-rf', 'log');
// t.pass();
// });
test.cb('logger test', t => {
shelljs.rm('-f', 'log/*.log.*');
logger.info('xxx', () => {
shelljs.ls('log/info.log.*').some(s => {
console.log('generate log file:' + s);
return s === 'info.log.' + today();
});
t.end();
test('logger error test', t => {
logger.error('error test', () => {
t.pass();
});
});
test('logger info test', t => {
logger.info('info test', () => {
t.pass();
});
});
... ...
... ... @@ -18,3 +18,12 @@ test('app sign test', t => {
t.true(sign.checkSign(signedParams));
});
test('app sign test webSign', t => {
let params = {
uid: '123',
key: '3fc5a9fcea9fea49cce5432202a167ad'
};
t.true(sign.webSign(params));
});
... ...