Authored by 陈峰

环境变量

@@ -54,7 +54,6 @@ const plugin = { @@ -54,7 +54,6 @@ const plugin = {
54 routes: routes, 54 routes: routes,
55 mode: Vue.$config.historyMode, 55 mode: Vue.$config.historyMode,
56 scrollBehavior(to, from, savedPosition) { 56 scrollBehavior(to, from, savedPosition) {
57 - console.log(savedPosition)  
58 if (savedPosition) { 57 if (savedPosition) {
59 return savedPosition; 58 return savedPosition;
60 } else if (to.hash) { 59 } else if (to.hash) {
@@ -16,18 +16,23 @@ const cookieSession = require('cookie-session'); @@ -16,18 +16,23 @@ const cookieSession = require('cookie-session');
16 const favicon = require('serve-favicon'); 16 const favicon = require('serve-favicon');
17 const path = require('path'); 17 const path = require('path');
18 18
  19 +
  20 +global.env = {
  21 + version: pkg.version,
  22 + Production: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'gray',
  23 + Test: (process.env.NODE_ENV || '').indexOf('test') >= 0
  24 +};
  25 +
  26 +let app = new Express();
  27 +
19 const config = require('./common/config'); 28 const config = require('./common/config');
20 const logger = require('yoho-node-lib/lib/logger').init(config); 29 const logger = require('yoho-node-lib/lib/logger').init(config);
21 const helpers = require('yoho-node-lib/lib/helpers'); 30 const helpers = require('yoho-node-lib/lib/helpers');
22 31
23 -let app = new Express();  
24 -  
25 global.yoho = { 32 global.yoho = {
26 logger, 33 logger,
27 helpers, 34 helpers,
28 - config,  
29 - apiDomain: config.apiDomain,  
30 - version: pkg.version 35 + config
31 }; 36 };
32 app.use(cookieSession({ 37 app.use(cookieSession({
33 name: 'yoho-shop', 38 name: 'yoho-shop',
@@ -66,16 +66,14 @@ const domains = { @@ -66,16 +66,14 @@ const domains = {
66 shop: 'http://192.168.102.211:30016' 66 shop: 'http://192.168.102.211:30016'
67 }; 67 };
68 68
69 -const isProd = process.env.NODE_ENV === 'production';  
70 -const isTest = (process.env.NODE_ENV || '').indexOf('test') >= 0;  
71 69
72 -if (isTest) { 70 +if (global.env.Test) {
73 domains.erp = 'http://192.168.103.82:9098'; 71 domains.erp = 'http://192.168.103.82:9098';
74 domains.platform = 'http://192.168.102.210:8088/platform'; 72 domains.platform = 'http://192.168.102.210:8088/platform';
75 domains.shop = 'http://192.168.102.211:30016'; 73 domains.shop = 'http://192.168.102.211:30016';
76 } 74 }
77 75
78 -if (isProd) { 76 +if (global.env.Production) {
79 domains.erp = 'http://gw.erp.yohoops.org'; 77 domains.erp = 'http://gw.erp.yohoops.org';
80 domains.platform = 'http://api.platform.yohoops.org/platform'; 78 domains.platform = 'http://api.platform.yohoops.org/platform';
81 domains.shop = 'http://shops.yohobuy.com'; 79 domains.shop = 'http://shops.yohobuy.com';
1 const Express = require('express'); 1 const Express = require('express');
2 let router = Express.Router(); // eslint-disable-line 2 let router = Express.Router(); // eslint-disable-line
3 const request = require('request'); 3 const request = require('request');
4 -const version = global.yoho.version; 4 +const env = global.env;
5 5
6 let mainProxy = (req, res) => { 6 let mainProxy = (req, res) => {
7 - request.get(`http://cdn.yoho.cn/yoho-shop-manage/${version}/index.html`).pipe(res); 7 + request.get(`http://cdn.yoho.cn/yoho-shop-manage/${env.version}/index.html`).pipe(res);
8 }; 8 };
9 9
10 router.get('/', mainProxy); 10 router.get('/', mainProxy);
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 const Api = require('../common/api'); 6 const Api = require('../common/api');
7 const _ = require('lodash'); 7 const _ = require('lodash');
8 const blacklist = require('../common/api-blacklist'); 8 const blacklist = require('../common/api-blacklist');
9 -const apiDomain = global.yoho.apiDomain; 9 +const config = global.yoho.config;
10 const logger = global.yoho.logger; 10 const logger = global.yoho.logger;
11 const apiReg = /^\/Api/; 11 const apiReg = /^\/Api/;
12 12
@@ -32,7 +32,7 @@ module.exports = (req, res, next) => { @@ -32,7 +32,7 @@ module.exports = (req, res, next) => {
32 }); 32 });
33 } 33 }
34 34
35 - let apiUrl = _.get(apiDomain, apiMap); 35 + let apiUrl = _.get(config.apiDomain, apiMap);
36 36
37 if (!apiUrl) { 37 if (!apiUrl) {
38 logger.error(`proxy [${req.method}] fail`, `${req.path} can't find proxy url`); 38 logger.error(`proxy [${req.method}] fail`, `${req.path} can't find proxy url`);
@@ -8,7 +8,6 @@ const _ = require('lodash'); @@ -8,7 +8,6 @@ const _ = require('lodash');
8 const Context = require('../framework/context'); 8 const Context = require('../framework/context');
9 const rp = require('request-promise'); 9 const rp = require('request-promise');
10 const Api = require('../common/api'); 10 const Api = require('../common/api');
11 -const apiDomain = global.yoho.apiDomain;  
12 const config = global.yoho.config; 11 const config = global.yoho.config;
13 12
14 const regSession = '${0}=([^;]+);'; 13 const regSession = '${0}=([^;]+);';
@@ -19,7 +18,7 @@ class UserService extends Context { @@ -19,7 +18,7 @@ class UserService extends Context {
19 this.api = this.instance(Api); 18 this.api = this.instance(Api);
20 } 19 }
21 login(account, password) { 20 login(account, password) {
22 - return this.api.post(apiDomain.erp.login, { 21 + return this.api.post(config.apiDomain.erp.login, {
23 account, 22 account,
24 password, 23 password,
25 platform: config.platform 24 platform: config.platform
@@ -33,7 +32,7 @@ class UserService extends Context { @@ -33,7 +32,7 @@ class UserService extends Context {
33 32
34 shopLogin(account, password) { 33 shopLogin(account, password) {
35 return rp.get({ 34 return rp.get({
36 - url: apiDomain.shop.login, 35 + url: config.apiDomain.shop.login,
37 resolveWithFullResponse: true, 36 resolveWithFullResponse: true,
38 qs: { 37 qs: {
39 user: account, 38 user: account,
@@ -61,7 +60,7 @@ class UserService extends Context { @@ -61,7 +60,7 @@ class UserService extends Context {
61 } 60 }
62 61
63 getShops(pid) { 62 getShops(pid) {
64 - return this.api.get(apiDomain.platform.queryShopsByAdminPid, { 63 + return this.api.get(config.apiDomain.platform.queryShopsByAdminPid, {
65 userId: pid 64 userId: pid
66 }).then(result => { 65 }).then(result => {
67 return result; 66 return result;
@@ -69,7 +68,7 @@ class UserService extends Context { @@ -69,7 +68,7 @@ class UserService extends Context {
69 } 68 }
70 69
71 profile(pid) { 70 profile(pid) {
72 - return this.instance(Api).get(apiDomain.shop.profile.url, {userId: pid}); 71 + return this.instance(Api).get(config.apiDomain.shop.profile.url, {userId: pid});
73 } 72 }
74 } 73 }
75 74