Authored by 陈峰

环境变量

... ... @@ -54,7 +54,6 @@ const plugin = {
routes: routes,
mode: Vue.$config.historyMode,
scrollBehavior(to, from, savedPosition) {
console.log(savedPosition)
if (savedPosition) {
return savedPosition;
} else if (to.hash) {
... ...
... ... @@ -16,18 +16,23 @@ const cookieSession = require('cookie-session');
const favicon = require('serve-favicon');
const path = require('path');
global.env = {
version: pkg.version,
Production: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'gray',
Test: (process.env.NODE_ENV || '').indexOf('test') >= 0
};
let app = new Express();
const config = require('./common/config');
const logger = require('yoho-node-lib/lib/logger').init(config);
const helpers = require('yoho-node-lib/lib/helpers');
let app = new Express();
global.yoho = {
logger,
helpers,
config,
apiDomain: config.apiDomain,
version: pkg.version
config
};
app.use(cookieSession({
name: 'yoho-shop',
... ...
... ... @@ -66,16 +66,14 @@ const domains = {
shop: 'http://192.168.102.211:30016'
};
const isProd = process.env.NODE_ENV === 'production';
const isTest = (process.env.NODE_ENV || '').indexOf('test') >= 0;
if (isTest) {
if (global.env.Test) {
domains.erp = 'http://192.168.103.82:9098';
domains.platform = 'http://192.168.102.210:8088/platform';
domains.shop = 'http://192.168.102.211:30016';
}
if (isProd) {
if (global.env.Production) {
domains.erp = 'http://gw.erp.yohoops.org';
domains.platform = 'http://api.platform.yohoops.org/platform';
domains.shop = 'http://shops.yohobuy.com';
... ...
const Express = require('express');
let router = Express.Router(); // eslint-disable-line
const request = require('request');
const version = global.yoho.version;
const env = global.env;
let mainProxy = (req, res) => {
request.get(`http://cdn.yoho.cn/yoho-shop-manage/${version}/index.html`).pipe(res);
request.get(`http://cdn.yoho.cn/yoho-shop-manage/${env.version}/index.html`).pipe(res);
};
router.get('/', mainProxy);
... ...
... ... @@ -6,7 +6,7 @@
const Api = require('../common/api');
const _ = require('lodash');
const blacklist = require('../common/api-blacklist');
const apiDomain = global.yoho.apiDomain;
const config = global.yoho.config;
const logger = global.yoho.logger;
const apiReg = /^\/Api/;
... ... @@ -32,7 +32,7 @@ module.exports = (req, res, next) => {
});
}
let apiUrl = _.get(apiDomain, apiMap);
let apiUrl = _.get(config.apiDomain, apiMap);
if (!apiUrl) {
logger.error(`proxy [${req.method}] fail`, `${req.path} can't find proxy url`);
... ...
... ... @@ -8,7 +8,6 @@ const _ = require('lodash');
const Context = require('../framework/context');
const rp = require('request-promise');
const Api = require('../common/api');
const apiDomain = global.yoho.apiDomain;
const config = global.yoho.config;
const regSession = '${0}=([^;]+);';
... ... @@ -19,7 +18,7 @@ class UserService extends Context {
this.api = this.instance(Api);
}
login(account, password) {
return this.api.post(apiDomain.erp.login, {
return this.api.post(config.apiDomain.erp.login, {
account,
password,
platform: config.platform
... ... @@ -33,7 +32,7 @@ class UserService extends Context {
shopLogin(account, password) {
return rp.get({
url: apiDomain.shop.login,
url: config.apiDomain.shop.login,
resolveWithFullResponse: true,
qs: {
user: account,
... ... @@ -61,7 +60,7 @@ class UserService extends Context {
}
getShops(pid) {
return this.api.get(apiDomain.platform.queryShopsByAdminPid, {
return this.api.get(config.apiDomain.platform.queryShopsByAdminPid, {
userId: pid
}).then(result => {
return result;
... ... @@ -69,7 +68,7 @@ class UserService extends Context {
}
profile(pid) {
return this.instance(Api).get(apiDomain.shop.profile.url, {userId: pid});
return this.instance(Api).get(config.apiDomain.shop.profile.url, {userId: pid});
}
}
... ...