Authored by 郭成尧

Merge branch 'feature/coupon' into release/180420

... ... @@ -157,3 +157,4 @@ nbproject/*
.scannerwork
package-lock.json
yarn.lock
yoho-yohobuy-wap.tar.gz
... ...
############################################################
# Dockerfile to build hystrix + turbin Installed Containers
# Based on centos 6.7
# How to build new image: docker build -t yoho-hystrix-qcloud .
# the hystrix alert need to post events to influxdb.yohoops.org.
# nginx version: 1.12.0
############################################################
#base image : ccr.ccs.tencentyun.com/yoho-base/nodejs:8.9.1
FROM ccr.ccs.tencentyun.com/yoho-base/nodejs:8.9.1
MAINTAINER xiaoxiao.hao <xiaoxiao.hao@yoho.cn>
ENV NODE_ENV=production \
NODE_HOME=/home
# COPY turbine configuration files
COPY yoho-yohobuy-wap.tar.gz /home
RUN cd /home && \
mkdir -p /home/yoho-yohobuy-wap && \
tar -xzvf yoho-yohobuy-wap.tar.gz -C /home/yoho-yohobuy-wap && \
rm -rf yoho-yohobuy-wap.tar.gz
WORKDIR /home/yoho-yohobuy-wap
#expose port
EXPOSE 6001
CMD ["node","/home/yoho-yohobuy-wap/app.js"]
... ...
... ... @@ -171,6 +171,11 @@ try {
app.use(downloadBar());
app.use(riskManagement());
// docker验证项目是否正常发布
app.use('/node/status.html', (req, res) => {
return res.status(204).end();
});
require('./dispatch')(app);
app.all('*', errorHanlder.notFound()); // 404
... ...
... ... @@ -44,5 +44,4 @@ router.get('/channel/2fb054e8315300a1ae1f80c3a4fda862.html', custom.zhihui);
// 自定义频道
router.get('/channel/:id.html', custom.index);
module.exports = router;
... ...
... ... @@ -412,7 +412,7 @@ function getRealIP(req) {
var realIP = req.headers['x-real-ip'];
var forwardedFor = req.headers['x-forwarded-for'] || '';
return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress;
return req.yoho.clientIp || forwardedFor.split(',')[0] || realIP || req.connection.remoteAddress;
}
const activateService = (req, res, next) => {
... ...
... ... @@ -197,10 +197,13 @@ const common = {
if (req.session2 && req.session2.reset) {
req.session2.reset();
}
if (req.session && req.session.regenerate) {
if (req.session && req.session.regenerate && req.sessionStore) {
return req.session.regenerate(() => {
return next();
});
} else {
return next();
}
// if (req.session) {
... ... @@ -210,7 +213,6 @@ const common = {
// delete req.session.TOKEN;
// delete req.session.LOGIN_UID;
// }
// return next();
},
isLoginUser: (req, res, next) => {
// 微信里边已经登录的时候,不再跳转登录
... ...
... ... @@ -67,12 +67,6 @@ module.exports = {
index: '//m.yohobuy.com'
},
useCache: false,
memcache: {
master: ['127.0.0.1:11211'],
session: ['127.0.0.1:11211'],
timeout: 1000,
retries: 0
},
interfaceShunt: {
open: false
},
... ... @@ -80,9 +74,12 @@ module.exports = {
infoFile: {
close: true,
name: 'info',
level: 'error',
level: 'info',
filename: 'logs/info.log',
maxFiles: 7
maxFiles: 7,
timestamp() {
return new Date().toString();
}
},
errorFile: {
close: true,
... ... @@ -90,7 +87,10 @@ module.exports = {
level: 'error',
filename: 'logs/error.log',
handleExceptions: true,
maxFiles: 7
maxFiles: 7,
timestamp() {
return new Date().toString();
}
},
console: {
level: 'debug',
... ... @@ -132,19 +132,27 @@ module.exports = {
connect: {
host: '127.0.0.1',
port: '6379',
password: '',
enable_offline_queue: false,
retry_strategy(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('redis连接不成功');
console.log('connect redis server fail');
}
if (options.total_retry_time > 1000 * 60 * 60 * 6) {
console.log('redis连接超时');
return;
}
if (options.attempt > 10) {
return 1000 * 60 * 60 * 0.5;
if (options.attempt < 10) {
return Math.min(options.attempt * 100, 1000);
} else if (options.attempt > 10 && options.attempt < 100) {
return 1000;
} else {
return 1000 * 10;
}
return Math.min(options.attempt * 100, 1000);
}
},
session: {
host: '127.0.0.1',
port: '6379',
pass: '',
prefix: 'yohobuy_session:'
}
},
REQUEST_LIMIT: {
... ... @@ -180,24 +188,6 @@ if (isProduction) {
extstore: 'http://extstore.yohobuy.com',
yohoNowApi: 'http://new.yohoboys.com/'
},
memcache: {
master: [
'memcache1.yohoops.org:12111',
'memcache2.yohoops.org:12111',
'memcache3.yohoops.org:12111',
'memcache4.yohoops.org:12111'
],
session: [
'memcache1.yohoops.org:12111',
'memcache2.yohoops.org:12111',
'memcache3.yohoops.org:12111',
'memcache4.yohoops.org:12111'
],
poolSize: 100,
reconnect: 5000,
timeout: 1000,
retries: 0
},
useCache: true,
interfaceShunt: {
open: false,
... ... @@ -226,21 +216,29 @@ if (isProduction) {
},
redis: {
connect: {
host: 'web.redis.yohoops.org'
},
port: '6379',
retry_strategy(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('redis连接不成功');
}
if (options.total_retry_time > 1000 * 60 * 60 * 6) {
console.log('redis连接超时');
return;
}
if (options.attempt > 10) {
return 1000 * 60 * 60 * 0.5;
host: 'redis.web.yohoops.org',
port: '6379',
password: 'redis9646',
enable_offline_queue: false,
retry_strategy(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('connect redis server fail');
}
if (options.attempt < 10) {
return Math.min(options.attempt * 100, 1000);
} else if (options.attempt > 10 && options.attempt < 100) {
return 1000;
} else {
return 1000 * 10;
}
}
return Math.min(options.attempt * 100, 1000);
},
session: {
host: 'redis.web.yohoops.org',
port: '6379',
pass: 'redis9646',
prefix: 'yohobuy_session:'
}
},
report: {
... ... @@ -250,21 +248,26 @@ if (isProduction) {
},
loggers: {
infoFile: {
close: true,
name: 'info',
level: 'error',
filename: 'logs/info.log',
maxFiles: 7
level: 'info',
filename: '/Data/log/yoho-yohobuy-wap/info.log',
maxFiles: 7,
timestamp() {
return new Date().toString();
}
},
errorFile: {
close: true,
name: 'error',
level: 'error',
filename: 'logs/error.log',
filename: '/Data/log/yoho-yohobuy-wap/error.log',
handleExceptions: true,
maxFiles: 7
maxFiles: 7,
timestamp() {
return new Date().toString();
}
},
console: {
close: true,
level: 'info',
colorize: 'all',
prettyPrint: true,
... ... @@ -287,13 +290,6 @@ if (isProduction) {
extstore: 'http://extstore-test1.yohops.com',
yohoNowApi: process.env.YOHO_NOW_API || 'http://yohonow-test.yohops.com:9999/'
},
memcache: {
master: ['127.0.0.1:12111'],
session: ['127.0.0.1:12111'],
timeout: 100,
reconnect: 5000,
retries: 0
},
useCache: true,
alipayConfig: {
payUrl: 'https://mapi.alipay.com/gateway.do',
... ...
#!/bin/bash
wordir=$2
cd $wordir
rm -rf yoho-yohobuy-wap.tar.gz
if [[ $1 == "TEST1" ]] || [[ $1 == "TEST2" ]] || [[ $1 == "TEST3" ]];then
yarn
yarn build
else
npm i --production
fi
tar -czvf yoho-yohobuy-wap.tar.gz *
... ...
... ... @@ -53,19 +53,7 @@ const limiter = (rule, policy, context) => {
};
module.exports = (req, res, next) => {
let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || '';
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[arr.length - 1];
}
remoteIp = _.trim(remoteIp);
if (_.startsWith(remoteIp, '10.66.')) {
remoteIp = req.get('X-Real-IP');
}
let remoteIp = req.yoho.clientIp || '';
// 排除条件:ip白名单/路径白名单/异步请求/登录用户
const excluded = _.includes(IP_WHITE_LIST, remoteIp) ||
... ...
... ... @@ -14,7 +14,7 @@ const net = require('net');
* @param {*} req
*/
const _getClientIp = req => {
let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip;
let remoteIp = req.get('X-Yoho-Real-IP') || req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip;
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
... ...
const config = global.yoho.config;
const memcachedSession = require('yoho-express-session');
const session = require('yoho-express-session');
const _ = require('lodash');
const uuid = require('uuid');
const cookieSession = require('client-sessions');
const memcached = require('connect-memcached');
const MemcachedStore = memcached(memcachedSession);
const connectRedis = require('connect-redis');
const RedisStore = connectRedis(session);
/**
* 该中间件主要把 express-session 和 client-session 集中起来处理,如果 memcached 出错了,使用 cookie session
* 该中间件主要把 express-session 和 client-session 集中起来处理,如果 redis 出错了,使用 cookie session
* @param opts.backSession cookieSession 的键名
* @returns {function(*=, *=, *)}
*/
function yohoSession(opts) {
return (req, res, next) => {
let notUseMemcached = _.get(req.app.locals.wap, 'session.removeMemcached', false);
let notUseRedis = _.get(req.app.locals.wap, 'session.removeMemcached', false);
opts.backSession = opts.backSession || 'session2';
if (req.session && !notUseMemcached) {
if (req.session && !notUseRedis) {
req.sessionError = false;
} else {
// 重建 session
... ... @@ -26,8 +26,8 @@ function yohoSession(opts) {
req.sessionError = true;
req.sessionID = req.sessionID || uuid.v4();
req.session = new memcachedSession.Session(req, req[opts.backSession].sessionBack);
req.session.cookie = new memcachedSession.Cookie({
req.session = new session.Session(req, req[opts.backSession].sessionBack);
req.session.cookie = new session.Cookie({
domain: 'yohobuy.com',
httpOnly: true
});
... ... @@ -51,7 +51,7 @@ function yohoSession(opts) {
}
module.exports = (app) => {
app.use(memcachedSession({ // eslint-disable-line
app.use(session({ // eslint-disable-line
proxy: true,
resave: false,
saveUninitialized: true,
... ... @@ -65,13 +65,7 @@ module.exports = (app) => {
domain: 'yohobuy.com',
httpOnly: true
},
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohobuy_session:',
reconnect: 5000,
timeout: 1000,
retries: 0
})
store: new RedisStore(config.redis.session)
}));
app.use(cookieSession({ // eslint-disable-line
... ...
{
"name": "yohobuywap-node",
"version": "6.5.35",
"version": "6.5.36",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ... @@ -46,8 +46,8 @@
"cheerio": "^0.22.0",
"client-sessions": "^0.8.0",
"compression": "^1.7.0",
"connect-memcached": "^0.2.0",
"connect-multiparty": "^2.0.0",
"connect-redis": "^3.3.3",
"cookie-parser": "^1.4.3",
"cssnano": "^3.10.0",
"express": "^4.15.4",
... ... @@ -74,7 +74,7 @@
"xml2js": "^0.4.19",
"yoho-express-session": "^2.0.0",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "=0.6.3",
"yoho-node-lib": "=0.6.8",
"yoho-zookeeper": "^1.0.9"
},
"devDependencies": {
... ...