nav tabs on admin dashboard
This commit is contained in:
+70
-67
@@ -1,54 +1,55 @@
|
||||
var _ = require('lodash');
|
||||
var url = require('url');
|
||||
var logger = require('./logger').getInstance();
|
||||
var _ = require('lodash')
|
||||
var url = require('url')
|
||||
var ERRORS = require('./errors')
|
||||
var logger = require('./logger').getInstance()
|
||||
|
||||
module.exports = {
|
||||
createConfig: createConfig
|
||||
};
|
||||
createConfig: createConfig
|
||||
}
|
||||
|
||||
function createConfig(context, opts) {
|
||||
// structure of config object to be returned
|
||||
var config = {
|
||||
context: undefined,
|
||||
options: {}
|
||||
};
|
||||
// structure of config object to be returned
|
||||
var config = {
|
||||
context: undefined,
|
||||
options: {}
|
||||
}
|
||||
|
||||
// app.use('/api', proxy({target:'http://localhost:9000'}));
|
||||
if (isContextless(context, opts)) {
|
||||
config.context = '/'
|
||||
config.options = _.assign(config.options, context)
|
||||
|
||||
// app.use('/api', proxy({target:'http://localhost:9000'}));
|
||||
if (isContextless(context, opts)) {
|
||||
config.context = '/';
|
||||
config.options = _.assign(config.options, context);
|
||||
}
|
||||
// app.use('/api', proxy('http://localhost:9000'));
|
||||
// app.use(proxy('http://localhost:9000/api'));
|
||||
else if (isStringShortHand(context)) {
|
||||
var oUrl = url.parse(context);
|
||||
var target = [oUrl.protocol, '//', oUrl.host].join('');
|
||||
} else if (isStringShortHand(context)) {
|
||||
var oUrl = url.parse(context)
|
||||
var target = [oUrl.protocol, '//', oUrl.host].join('')
|
||||
|
||||
config.context = oUrl.pathname || '/';
|
||||
config.options = _.assign(config.options, {target: target}, opts);
|
||||
config.context = oUrl.pathname || '/'
|
||||
config.options = _.assign(config.options, { target: target }, opts)
|
||||
|
||||
if (oUrl.protocol === 'ws:' || oUrl.protocol === 'wss:') {
|
||||
config.options.ws = true;
|
||||
}
|
||||
if (oUrl.protocol === 'ws:' || oUrl.protocol === 'wss:') {
|
||||
config.options.ws = true
|
||||
}
|
||||
// app.use('/api', proxy({target:'http://localhost:9000'}));
|
||||
} else {
|
||||
config.context = context;
|
||||
config.options = _.assign(config.options, opts);
|
||||
}
|
||||
} else {
|
||||
config.context = context
|
||||
config.options = _.assign(config.options, opts)
|
||||
}
|
||||
|
||||
configureLogger(config.options);
|
||||
configureLogger(config.options)
|
||||
|
||||
if (!config.options.target) {
|
||||
throw new Error('[HPM] Missing "target" option. Example: {target: "http://www.example.org"}');
|
||||
}
|
||||
if (!config.options.target) {
|
||||
throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING)
|
||||
}
|
||||
|
||||
// Legacy option.proxyHost
|
||||
config.options = mapLegacyProxyHostOption(config.options);
|
||||
// Legacy option.proxyHost
|
||||
config.options = mapLegacyProxyHostOption(config.options)
|
||||
|
||||
// Legacy option.proxyTable > option.router
|
||||
config.options = mapLegacyProxyTableOption(config.options);
|
||||
// Legacy option.proxyTable > option.router
|
||||
config.options = mapLegacyProxyTableOption(config.options)
|
||||
|
||||
return config;
|
||||
return config
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +64,9 @@ function createConfig(context, opts) {
|
||||
* @return {Boolean} [description]
|
||||
*/
|
||||
function isStringShortHand(context) {
|
||||
if (_.isString(context)) {
|
||||
return (url.parse(context).host) ? true : false;
|
||||
}
|
||||
if (_.isString(context)) {
|
||||
return !!url.parse(context).host
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,47 +81,49 @@ function isStringShortHand(context) {
|
||||
* @return {Boolean} [description]
|
||||
*/
|
||||
function isContextless(context, opts) {
|
||||
return (_.isPlainObject(context) && _.isEmpty(opts));
|
||||
return _.isPlainObject(context) && _.isEmpty(opts)
|
||||
}
|
||||
|
||||
function mapLegacyProxyHostOption(options) {
|
||||
// set options.headers.host when option.proxyHost is provided
|
||||
if (options.proxyHost) {
|
||||
logger.warn('*************************************');
|
||||
logger.warn('[HPM] Deprecated "option.proxyHost"');
|
||||
logger.warn(' Use "option.changeOrigin" or "option.headers.host" instead');
|
||||
logger.warn(' "option.proxyHost" will be removed in future release.');
|
||||
logger.warn('*************************************');
|
||||
// set options.headers.host when option.proxyHost is provided
|
||||
if (options.proxyHost) {
|
||||
logger.warn('*************************************')
|
||||
logger.warn('[HPM] Deprecated "option.proxyHost"')
|
||||
logger.warn(
|
||||
' Use "option.changeOrigin" or "option.headers.host" instead'
|
||||
)
|
||||
logger.warn(' "option.proxyHost" will be removed in future release.')
|
||||
logger.warn('*************************************')
|
||||
|
||||
options.headers = options.headers || {};
|
||||
options.headers.host = options.proxyHost;
|
||||
}
|
||||
options.headers = options.headers || {}
|
||||
options.headers.host = options.proxyHost
|
||||
}
|
||||
|
||||
return options;
|
||||
return options
|
||||
}
|
||||
|
||||
// Warn deprecated proxyTable api usage
|
||||
function mapLegacyProxyTableOption(options) {
|
||||
if (options.proxyTable) {
|
||||
logger.warn('*************************************');
|
||||
logger.warn('[HPM] Deprecated "option.proxyTable"');
|
||||
logger.warn(' Use "option.router" instead');
|
||||
logger.warn(' "option.proxyTable" will be removed in future release.');
|
||||
logger.warn('*************************************');
|
||||
if (options.proxyTable) {
|
||||
logger.warn('*************************************')
|
||||
logger.warn('[HPM] Deprecated "option.proxyTable"')
|
||||
logger.warn(' Use "option.router" instead')
|
||||
logger.warn(' "option.proxyTable" will be removed in future release.')
|
||||
logger.warn('*************************************')
|
||||
|
||||
options.router = _.clone(options.proxyTable);
|
||||
_.omit(options, 'proxyTable');
|
||||
}
|
||||
options.router = _.clone(options.proxyTable)
|
||||
_.omit(options, 'proxyTable')
|
||||
}
|
||||
|
||||
return options;
|
||||
return options
|
||||
}
|
||||
|
||||
function configureLogger(options) {
|
||||
if (options.logLevel) {
|
||||
logger.setLevel(options.logLevel);
|
||||
}
|
||||
if (options.logLevel) {
|
||||
logger.setLevel(options.logLevel)
|
||||
}
|
||||
|
||||
if (options.logProvider) {
|
||||
logger.setProvider(options.logProvider);
|
||||
}
|
||||
if (options.logProvider) {
|
||||
logger.setProvider(options.logProvider)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user