Authored by biao

update for app.js and confing.js

@@ -12,22 +12,26 @@ if (config.useOneapm) { @@ -12,22 +12,26 @@ if (config.useOneapm) {
12 require('oneapm'); 12 require('oneapm');
13 } 13 }
14 14
15 -let express = require('express'),  
16 - path = require('path'),  
17 - bodyParser = require('body-parser'),  
18 - cookieParser = require('cookie-parser'),  
19 - favicon = require('serve-favicon'),  
20 - pkg = require('./package.json'); 15 +const express = require('express');
  16 +const path = require('path');
  17 +const bodyParser = require('body-parser');
  18 +const cookieParser = require('cookie-parser');
  19 +const favicon = require('serve-favicon');
  20 +const session = require('express-session');
  21 +const memcached = require('connect-memcached');
  22 +const pkg = require('./package.json');
21 23
22 -require('express-handlebars'); 24 +const app = express();
  25 +const MemcachedStore = memcached(session);
23 26
24 27
25 -let app = express();  
26 -  
27 // 向模板注入变量 28 // 向模板注入变量
28 app.locals.devEnv = app.get('env') === 'development'; 29 app.locals.devEnv = app.get('env') === 'development';
29 app.locals.version = pkg.version; 30 app.locals.version = pkg.version;
30 31
  32 +// 指定libray目录
  33 +global.library = path.resolve('./library');
  34 +
31 app.set('view engine', '.hbs'); 35 app.set('view engine', '.hbs');
32 36
33 app.use(favicon(path.join(__dirname, '/public/favicon.ico'))); 37 app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
@@ -35,11 +39,22 @@ app.use(express.static(path.join(__dirname, 'public'))); @@ -35,11 +39,22 @@ app.use(express.static(path.join(__dirname, 'public')));
35 app.use(bodyParser.json()); 39 app.use(bodyParser.json());
36 app.use(bodyParser.urlencoded({extended: false})); 40 app.use(bodyParser.urlencoded({extended: false}));
37 app.use(cookieParser()); 41 app.use(cookieParser());
  42 +app.use(session({
  43 + secret: '3e5fec7deca0b8305cefe2ad9d90ff5e',
  44 + name: 'PHPSESSID',
  45 + prefix: 'yohobuy',
  46 + proxy: true,
  47 + resave: true,
  48 + saveUninitialized: true,
  49 + store: new MemcachedStore({
  50 + hosts: config.memcache.session
  51 + })
  52 +}));
38 53
39 // dispatcher 54 // dispatcher
40 require('./dispatch')(app); 55 require('./dispatch')(app);
41 56
42 // listener 57 // listener
43 -app.listen(6001, function() { 58 +app.listen(config.port, function() {
44 console.log('yohobuy start'); 59 console.log('yohobuy start');
45 }); 60 });
@@ -10,11 +10,20 @@ const isProduction = process.env.NODE_ENV === 'production'; @@ -10,11 +10,20 @@ const isProduction = process.env.NODE_ENV === 'production';
10 const isTest = process.env.NODE_ENV === 'test'; 10 const isTest = process.env.NODE_ENV === 'test';
11 11
12 module.exports = { 12 module.exports = {
  13 + port: 6001,
13 siteUrl: 'http://m.yohobuy.com', 14 siteUrl: 'http://m.yohobuy.com',
14 domains: { 15 domains: {
15 api: 'http://testapi.yoho.cn:28078/', // http://devapi.yoho.cn:58078/ http://testapi.yoho.cn:28078/ 16 api: 'http://testapi.yoho.cn:28078/', // http://devapi.yoho.cn:58078/ http://testapi.yoho.cn:28078/
16 service: 'http://devapi.yoho.cn:58078/' 17 service: 'http://devapi.yoho.cn:58078/'
17 }, 18 },
  19 + useOneapm: false,
  20 + useCache: true,
  21 + memcache: {
  22 + master: ['192.168.102.168:12580'],
  23 + slave: ['192.168.102.168:12580'],
  24 + session: ['192.168.102.168:12580'],
  25 + timeout: 5000
  26 + },
18 loggers: { 27 loggers: {
19 infoFile: { 28 infoFile: {
20 name: 'info', 29 name: 'info',
@@ -31,9 +31,11 @@ @@ -31,9 +31,11 @@
31 "license": "MIT", 31 "license": "MIT",
32 "dependencies": { 32 "dependencies": {
33 "body-parser": "^1.15.0", 33 "body-parser": "^1.15.0",
  34 + "connect-memcached": "^0.2.0",
34 "cookie-parser": "^1.4.1", 35 "cookie-parser": "^1.4.1",
35 "express": "^4.13.1", 36 "express": "^4.13.1",
36 "express-handlebars": "^3.0.0", 37 "express-handlebars": "^3.0.0",
  38 + "express-session": "^1.13.0",
37 "influxdb-winston": "^1.0.1", 39 "influxdb-winston": "^1.0.1",
38 "lodash": "^4.12.0", 40 "lodash": "^4.12.0",
39 "md5": "^2.1.0", 41 "md5": "^2.1.0",