react-cosmos
Version:
CLI for running React Cosmos inside webpack-powered apps
31 lines (25 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.httpProxy = httpProxy;
var _httpProxyMiddleware = require("http-proxy-middleware");
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function httpProxy(_ref) {
var cosmosConfig = _ref.cosmosConfig,
expressApp = _ref.expressApp;
var httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
Object.keys(httpProxyConfig).forEach(function (context) {
var config = httpProxyConfig[context];
if (typeof config === 'string') {
expressApp.use(context, (0, _httpProxyMiddleware.createProxyMiddleware)(context, {
target: config
}));
} else if (_typeof(config) === 'object') {
expressApp.use(context, (0, _httpProxyMiddleware.createProxyMiddleware)(context, config));
}
});
}
function getHttpProxyCosmosConfig(cosmosConfig) {
return cosmosConfig.httpProxy || {};
}