From 11c339f636075c56b4cd1752d8b3ba8afcd54657 Mon Sep 17 00:00:00 2001 From: Jack Hu Date: Sun, 2 Oct 2016 19:43:55 +0800 Subject: [PATCH] modify config and add Dockerfile --- .dockerignore | 6 ++++ Dockerfile | 6 ++++ README.md | 3 +- logs/test-error.log.0 | 28 +++++++++-------- logs/test-error.log.1 | 12 ++++++++ package.json | 6 ++-- process.json | 20 ++++++------ server/auth/auth.service.js | 2 +- server/config/env/index.js | 54 +++++++++++++++------------------ server/config/env/production.js | 15 +++++---- server/model/user.model.js | 2 +- test/api/article.test.js | 2 +- 12 files changed, 88 insertions(+), 68 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 logs/test-error.log.1 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e52b280 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +*.md +.git +node_modules +test +test_coverage +gulp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3a68e41 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM jackhu/jenkins-deploy-nodejs:6 +MAINTAINER Jack Hu + +EXPOSE 8800 + +CMD ["npm","run","pm2-start"] \ No newline at end of file diff --git a/README.md b/README.md index c1a2508..746c39a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## 简介 Jackblog 是使用 Node.js + MongoDB + Redis + 其它客户端框架开发的个人博客系统,前后端分离,仿简书模板. 服务端有: [express 版](https://github.com/jackhutu/jackblog-api-express) , [koa 版](https://github.com/jackhutu/jackblog-api-koa) -客户端有: [angular1.x 版](https://github.com/jackhutu/jackblog-angular1) , [angular2.x 版](https://github.com/jackhutu/jackblog-angular2) , [react redux 版](https://github.com/jackhutu/jackblog-react-redux) , [vue 版](https://github.com/jackhutu/jackblog-vue) +客户端有: [angular1.x 版](https://github.com/jackhutu/jackblog-angular1) , [angular2.x 版](https://github.com/jackhutu/jackblog-angular2) , [react 版](https://github.com/jackhutu/jackblog-react) , [vue 版](https://github.com/jackhutu/jackblog-vue) 移动端有: [react native 版](https://github.com/jackhutu/jackblog-react-native-redux), [ionic2.0 版](https://github.com/jackhutu/jackblog-ionic2) ##### 此为服务端Express版, 为客户端提供api. @@ -66,7 +66,6 @@ redis for windows 只支持64位的操作系统 ``` $ pm2 start process.json ``` -可参考[利用git和pm2一键布署项目到vps](http://jackhu.top/article/55cd8e00c6e998b817a930c7) ## 测试 ``` diff --git a/logs/test-error.log.0 b/logs/test-error.log.0 index 36e8454..dcb389d 100644 --- a/logs/test-error.log.0 +++ b/logs/test-error.log.0 @@ -1,12 +1,16 @@ -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"登录密码错误 { username: 'test011462017778089@tets.com' }","time":"2016-04-30T12:03:00.298Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T12:03:00.305Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"未验证用户登录 { username: 'test021462017778089@tets.com' }","time":"2016-04-30T12:03:00.351Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"被阻止登录 { username: 'test031462017778089@tets.com' }","time":"2016-04-30T12:03:00.401Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"登录密码错误 { username: 'test011462017814522@tets.com' }","time":"2016-04-30T12:03:36.496Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T12:03:36.503Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"未验证用户登录 { username: 'test021462017814522@tets.com' }","time":"2016-04-30T12:03:36.557Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"被阻止登录 { username: 'test031462017814522@tets.com' }","time":"2016-04-30T12:03:36.617Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"登录密码错误 { username: 'test011462030073625@tets.com' }","time":"2016-04-30T15:27:55.932Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T15:27:55.940Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"未验证用户登录 { username: 'test021462030073625@tets.com' }","time":"2016-04-30T15:27:55.990Z","v":0} -{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"被阻止登录 { username: 'test031462030073625@tets.com' }","time":"2016-04-30T15:27:56.039Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":12961,"level":50,"msg":"登录密码错误 { username: 'test011468295297285@tets.com' }","time":"2016-07-12T03:48:20.159Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":12961,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-07-12T03:48:20.167Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":12961,"level":50,"msg":"未验证用户登录 { username: 'test021468295297285@tets.com' }","time":"2016-07-12T03:48:20.232Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":12961,"level":50,"msg":"被阻止登录 { username: 'test031468295297285@tets.com' }","time":"2016-07-12T03:48:20.304Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":16801,"level":50,"msg":"登录密码错误 { username: 'test011468299739724@tets.com' }","time":"2016-07-12T05:02:21.843Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":16801,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-07-12T05:02:21.850Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":16801,"level":50,"msg":"未验证用户登录 { username: 'test021468299739724@tets.com' }","time":"2016-07-12T05:02:21.907Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":16801,"level":50,"msg":"被阻止登录 { username: 'test031468299739724@tets.com' }","time":"2016-07-12T05:02:21.950Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":35649,"level":50,"msg":"登录密码错误 { username: 'test011468325216943@tets.com' }","time":"2016-07-12T12:06:59.412Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":35649,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-07-12T12:06:59.423Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":35649,"level":50,"msg":"未验证用户登录 { username: 'test021468325216943@tets.com' }","time":"2016-07-12T12:06:59.478Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":35649,"level":50,"msg":"被阻止登录 { username: 'test031468325216943@tets.com' }","time":"2016-07-12T12:06:59.533Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":36146,"level":50,"msg":"登录密码错误 { username: 'test011468325883651@tets.com' }","time":"2016-07-12T12:18:05.802Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":36146,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-07-12T12:18:05.809Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":36146,"level":50,"msg":"未验证用户登录 { username: 'test021468325883651@tets.com' }","time":"2016-07-12T12:18:05.862Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":36146,"level":50,"msg":"被阻止登录 { username: 'test031468325883651@tets.com' }","time":"2016-07-12T12:18:05.908Z","v":0} diff --git a/logs/test-error.log.1 b/logs/test-error.log.1 new file mode 100644 index 0000000..36e8454 --- /dev/null +++ b/logs/test-error.log.1 @@ -0,0 +1,12 @@ +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"登录密码错误 { username: 'test011462017778089@tets.com' }","time":"2016-04-30T12:03:00.298Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T12:03:00.305Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"未验证用户登录 { username: 'test021462017778089@tets.com' }","time":"2016-04-30T12:03:00.351Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15951,"level":50,"msg":"被阻止登录 { username: 'test031462017778089@tets.com' }","time":"2016-04-30T12:03:00.401Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"登录密码错误 { username: 'test011462017814522@tets.com' }","time":"2016-04-30T12:03:36.496Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T12:03:36.503Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"未验证用户登录 { username: 'test021462017814522@tets.com' }","time":"2016-04-30T12:03:36.557Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":15992,"level":50,"msg":"被阻止登录 { username: 'test031462017814522@tets.com' }","time":"2016-04-30T12:03:36.617Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"登录密码错误 { username: 'test011462030073625@tets.com' }","time":"2016-04-30T15:27:55.932Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"登录用户名错误 { username: 'ttttt@ttttt.com' }","time":"2016-04-30T15:27:55.940Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"未验证用户登录 { username: 'test021462030073625@tets.com' }","time":"2016-04-30T15:27:55.990Z","v":0} +{"name":"hutublog","hostname":"hugongzideMacBook-Air.local","pid":24693,"level":50,"msg":"被阻止登录 { username: 'test031462030073625@tets.com' }","time":"2016-04-30T15:27:56.039Z","v":0} diff --git a/package.json b/package.json index 804ec71..9ea2797 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { "name": "jackblog-api-express", - "version": "1.3.2", + "version": "1.3.3", "description": "Jackblog API Express版", "main": "server/app.js", "scripts": { "test": "gulp test", "start": "gulp serve", - "pm2-start": "pm2 start process.json", - "pm2-restart": "pm2 restart process.json" + "pm2-start": "pm2 start --no-daemon process.json" }, "repository": { "type": "git", @@ -49,7 +48,6 @@ "passport-local": "^1.0.0", "passport-qq": "0.0.3", "passport-weibo": "^0.1.2", - "pm2": "^1.1.3", "qiniu": "^6.1.11" }, "devDependencies": { diff --git a/process.json b/process.json index 7b5ac94..6dc0817 100644 --- a/process.json +++ b/process.json @@ -1,17 +1,17 @@ { "apps": [ { - "name" : "jackblog-api", - "script" : "./server/app.js", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "out_file" : "./logs/pm2-out.log", - "error_file" : "./logs/pm2-err.log", - "pid_file" : "./logs/jackblog-api.pid", - "ignoreWatch" : ["[\\/\\\\]\\./", "node_modules"], - "watch" : "false", - "exec_mode" : "fork_mode", //cluster_mode + "name" : "jackblog-api", + "script" : "./server/app.js", + "log_date_format" : "YYYY-MM-DD HH:mm Z", + "out_file" : "./logs/pm2-out.log", + "error_file" : "./logs/pm2-err.log", + "pid_file" : "./logs/jackblog-api.pid", + "ignoreWatch" : ["[\\/\\\\]\\./", "node_modules"], + "watch" : "false", + "exec_mode" : "fork_mode", //cluster_mode "env": { - "NODE_ENV": "production" + "NODE_ENV" : "production" } } ] diff --git a/server/auth/auth.service.js b/server/auth/auth.service.js index 10a0bc4..20c4a6a 100644 --- a/server/auth/auth.service.js +++ b/server/auth/auth.service.js @@ -14,7 +14,7 @@ var User = mongoose.model('User'); function authToken(credentialsRequired) { return compose() .use(function(req, res, next) { - if(req.query && req.query.hasOwnProperty('access_token')) { + if(req.query && req.query.access_token) { req.headers.authorization = 'Bearer ' + req.query.access_token; } next(); diff --git a/server/config/env/index.js b/server/config/env/index.js index d19c84c..03b8a81 100644 --- a/server/config/env/index.js +++ b/server/config/env/index.js @@ -11,15 +11,15 @@ var all = { //mongodb配置 mongo: { options: { - db: { - safe: true - } + user: process.env.MONGO_USERNAME || '', + pass: process.env.MONGO_PASSWORD || '' } }, //redis 配置 redis: { - host: '127.0.0.1', - port: 6379 + host: process.env.REDIS_PORT_6379_TCP_ADDR || '127.0.0.1', + port: process.env.REDIS_PORT_6379_TCP_PORT || 6379, + password: process.env.REDIS_PASSWORD || '' }, //是否初始化数据 seedDB: false, @@ -30,48 +30,48 @@ var all = { userRoles: ['user', 'admin'], //七牛配置 qiniu:{ - app_key:'', - app_secret:'', - domain:'', //七牛配置域名 - bucket:'' //七牛空间名称 + app_key: process.env.QINIU_APP_KEY || '', + app_secret: process.env.QINIU_APP_SECRET || '', + domain: process.env.QINIU_APP_DOMAIN || '', //七牛配置域名 + bucket: process.env.QINIU_APP_BUCKET || '' //七牛空间名称 }, //默认首页图片. - defaultIndexImage:"http://upload.jackhu.top/blog/index/8x7hVJvpE3Z6ruwgtd2G.jpg", + defaultIndexImage: 'https://upload.jackhu.top/blog/index/default.jpg-600x1500q80', //第三方登录配置 github:{ - clientID:"github", - clientSecret:"clientSecret", - callback:"/auth/github/callback" + clientID: process.env.GITHUB_CLIENT_ID || 'clientID', + clientSecret: process.env.GITHUB_CLIENT_SECRET || 'clientSecret', + callbackURL: process.env.GITHUB_CALLBACK_URL || '', }, weibo:{ - clientID:"clientID", - clientSecret:"clientSecret", - callbackURL:"/auth/weibo/callback" + clientID: process.env.WEIBO_CLIENT_ID || 'clientID', + clientSecret: process.env.WEIBO_CLIENT_SECRET || 'clientSecret', + callbackURL: process.env.WEIBO_CALLBACK_URL || '', }, qq:{ - clientID:"clientID", - clientSecret:"clientSecret", - callbackURL:"/auth/qq/callback" + clientID: process.env.QQ_CLIENT_ID || 'clientID', + clientSecret: process.env.QQ_CLIENT_SECRET || 'clientSecret', + callbackURL: process.env.QQ_CALLBACK_URL || '', }, //移动APP列表 apps:[ { name:'React Native', - gitUrl:'http://github.com/jackhutu/jackblog-react-native-redux', + gitUrl:'//github.com/jackhutu/jackblog-react-native-redux', downloadUrl:{ - android:'http://a.app.qq.com/o/simple.jsp?pkgname=top.jackhu.reactnative', + android:'//a.app.qq.com/o/simple.jsp?pkgname=top.jackhu.reactnative', ios:'' }, - qrcode:'http://upload.jackhu.top/qrcode/jackblog-react-native-qrcode.png' + qrcode:'https://upload.jackhu.top/qrcode/jackblog-react-native-qrcode.png' }, { name:'Ionic 2.0', - gitUrl:'http://github.com/jackhutu/jackblog-ionic2', + gitUrl:'//github.com/jackhutu/jackblog-ionic2', downloadUrl:{ - android:'http://upload.jackhu.top/downloads/Jackblog-ionic2-1.0.0.apk', + android:'https://upload.jackhu.top/downloads/Jackblog-ionic2-1.0.0.apk', ios:'' }, - qrcode:'http://upload.jackhu.top/qrcode/jackblog-ionic2-v1.0.0.png' + qrcode:'https://upload.jackhu.top/qrcode/jackblog-ionic2-v1.0.0.png' } ], //开启第三方登录 @@ -79,8 +79,4 @@ var all = { }; var config = _.merge(all,require('./' + process.env.NODE_ENV + '.js') || {}); -//加载私有配置 -if (fs.existsSync(path.join(__dirname, 'private/index.js'))) { - config = _.merge(config, require(path.join(__dirname, 'private/index.js')) || {}); -} module.exports = config; diff --git a/server/config/env/production.js b/server/config/env/production.js index 127b4c3..36405ec 100644 --- a/server/config/env/production.js +++ b/server/config/env/production.js @@ -2,22 +2,21 @@ // 生产环境配置 // ================================= +var MONGO_ADDR = process.env.MONGO_PORT_27017_TCP_ADDR || "localhost"; + module.exports = { - port: process.env.PORT || 8800, + port: process.env.PORT || 8800, //生产环境mongodb配置 mongo: { - uri: 'mongodb://localhost/jackblog', - options: { - user:'user', //生产环境用户名 - pass:'pass' //生产环境密码 - } + uri: 'mongodb://' + MONGO_ADDR + '/jackblog' }, //生产环境redis配置 redis: { - db: 1 + db: 1, + dropBufferSupport: true }, //生产环境cookie是否需要domain视具体情况而定. session:{ - cookie: {domain:'.jackhu.top',maxAge: 60000*5} + cookie: {domain:'.jackhu.top',maxAge: 60000*5} } }; diff --git a/server/model/user.model.js b/server/model/user.model.js index 04a99ed..2b3f982 100644 --- a/server/model/user.model.js +++ b/server/model/user.model.js @@ -167,7 +167,7 @@ UserSchema.methods = { encryptPassword: function(password) { if (!password || !this.salt) return ''; var salt = new Buffer(this.salt, 'base64'); - return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64'); + return crypto.pbkdf2Sync(password, salt, 10000, 64, 'sha1').toString('base64'); } } diff --git a/test/api/article.test.js b/test/api/article.test.js index 275dc32..f030805 100644 --- a/test/api/article.test.js +++ b/test/api/article.test.js @@ -364,7 +364,7 @@ describe('test/api/article.test.js',function () { .end(function (err,res) { if (err) return done(err); res.body.success.should.be.true(); - res.body.img.should.startWith('http://upload.jackhu.top'); + res.body.img.should.startWith('https://upload.jackhu.top'); stubQiniu.calledOnce.should.be.true(); done(); });