index.js 5.13 KB
'use strict';

var fs = require('fs');
var path = require('path');
var session = require('express-session');
var Redis = require('connect-redis')(session);

var config = JSON.parse(fs.readFileSync('./package.json').toString());

var grayroute = require("./mid/grayrouter");

/*session 配置*/
var options = {
    secret: 'yohobuy.portal', //session配置
	// cookie: {secure: false, maxAge: 7200000},
    cookie: {secure: false, maxAge: 7200000, domain: '.yohobuy.com'},
    resave: false,
    saveUninitialized: true,
    rolling: true
};

/*老平台接口 配置*/
var oldSerDomain = 'http://serve.yohobuy.com';
//var javaErpDomain = 'http://gateway.erp.yohoops.org';
var javaErpDomain = 'http://192.168.103.48:9098';
var Iaccount = {
    WEBSITE: 1,
    login: oldSerDomain + '/service/account/v1/Profile/login',
    loginEx: javaErpDomain + '/erp-gateway-web/account/profile/login',
    getResourceByPid: oldSerDomain + '/service/account/v1/Profile/getMenuByPid',
    getAllResByWebsite: oldSerDomain + '/service/setting/v1/menu/getAllMenu',
    changeShops: 'http://shops.yohobuy.com/index/ajaxshop',
    isUsedMenuAuth: oldSerDomain + '/service/account/v1/profile/authPath',
    allRight: oldSerDomain + '/service/setting/v1/action/getAllAction',

    getShopList: '{{domain}}/ShopsRest/queryShopsByAdminPid',
    
    // 灰度代理
    url: 'http://admin.portal.yohobuy.com',
    sessionKeep: '/account/profile/display',
    timeout: 10000,

    queryAllAuth : javaErpDomain + '/erp-gateway-web/account/profileDataEntitlement/queryAllAuth'
};



/*框架配置*/
var apiCofig = {
	//root:__dirname,
	EnvConst:{
		  //domain:"http://127.0.0.1:8088/platform",
		domain:"http://java-yoho-platform.test3.ingress.dev.yohocorp.com/platform",
		// domain:"http://172.16.6.200:8088/platform",
		//domain:"http://192.168.102.202:8088/platform",

		yohoSearch: 'http://192.168.102.216:8080/yohosearch',
		system:Iaccount
	},
	apps:path.join(__dirname,"apps"),
    port: 30012,
	log:{
		consoles:['log', 'info', 'warn', 'error'],
		src:path.join(__dirname,"..","logs")
	},
	mock:false,
	baseUrl:'/',
	static: {name:"static",value: '../dist/'+config.name+'/'+ config.version},
    MVC: {
        //开发环境
		Interfacer:path.join(__dirname,"apps/0/interfaces/1.js").replace(/0|1/g,'*'),
		Controller:path.join(__dirname,"apps/0/controllers/1.js").replace(/0|1/g,'*'),
        filters: path.join(__dirname, "filters.js"),
        views: path.resolve(__dirname,"apps", "0", "views/1")
	},
	useToEntry:function(app){
		if(process.env.NODE_ENV!="coding"&&process.env.NODE_ENV!=="test"){
			options.store=new Redis({
	            port: 6379,
	            host: 'redis.platform.yohoops.org'
	        });
		}

		if(process.env.NODE_ENV==="gray"){
			options.cookie.domain = '';
		}

		if(process.env.NODE_ENV==="production"){
			options.cookie.domain = '.yohobuy.com';
		}

		app.use(session(options));
	},
	useToOuter:function(app,controllers){
		app.use(grayroute(controllers));
	}
};

console.log("环境:"+process.env.NODE_ENV);

if(process.env.NODE_ENV!=='development'){
	apiCofig.log.src="/Data/logs/node/yohobuy-portal-log/"
}

/*服务器环境*/
if(process.env.NODE_ENV!="coding"){
	console.log("服务器环境");
	apiCofig.MVC={
		Interfacer:path.join(__dirname,"interfaces/0.js").replace(/0/g,'*'),
		Controller:path.join(__dirname,"controllers/0.js").replace(/0/g,'*'),
        filters: path.join(__dirname, "filters.js"),
        views: path.resolve(__dirname,"views", "0", "1")
	}
}
/*线下测试环境*/
 if(process.env.NODE_ENV==="test211"){
 	apiCofig.EnvConst.domain="http://192.168.102.202:8088/platform";
 	apiCofig.EnvConst.yohoSearch="http://192.168.102.216:8080/yohosearch";
 	Iaccount.loginEx = "http://gateway.erp.yohoops.org:9098/erp-gateway-web/account/profile/login";
 	Iaccount.queryAllAuth = "http://gateway.erp.yohoops.org:9098/erp-gateway-web/account/profileDataEntitlement/queryAllAuth";
 }

/*测试环境*/
if(process.env.NODE_ENV==="test"){
	apiCofig.EnvConst.domain=process.env.TEST_PLATFORM||"http://10.66.100.6:8088/platform";
	apiCofig.EnvConst.yohoSearch=process.env.TEST_SEARCH||"http://10.66.100.4:8080/yohosearch";
	Iaccount.loginEx = "http://qrest.yohobuy.com:9098/erp-gateway-web/account/profile/login";
 	Iaccount.queryAllAuth = "http://qrest.yohobuy.com:9098/erp-gateway-web/account/profileDataEntitlement/queryAllAuth";
}

/*灰度环境*/
if(process.env.NODE_ENV==="gray"){
	apiCofig.EnvConst.domain="http://apigray.platform.yohoops.org:8088/platform";
	apiCofig.EnvConst.yohoSearch="http://search.yohoops.org/yohosearch";
	Iaccount.loginEx = "http://gateway.erp.yohoops.org/erp-gateway-web/account/profile/login";
 	Iaccount.queryAllAuth = "http://gateway.erp.yohoops.org/erp-gateway-web/account/profileDataEntitlement/queryAllAuth";
}
/*线上环境*/
if(process.env.NODE_ENV==="production"){
	apiCofig.EnvConst.domain="http://api.platform.yohoops.org:8088/platform";
	apiCofig.EnvConst.yohoSearch="http://search.yohoops.org/yohosearch";
	Iaccount.loginEx = "http://gateway.erp.yohoops.org/erp-gateway-web/account/profile/login";
 	Iaccount.queryAllAuth = "http://gateway.erp.yohoops.org/erp-gateway-web/account/profileDataEntitlement/queryAllAuth";
}
module.exports = require('./libs/App')(apiCofig);