@useoptic/cli-config
Advanced tools
Comparing version 8.1.1 to 8.2.0
@@ -17,2 +17,3 @@ import { parseRule, parseIgnore, IIgnoreRunnable } from './helpers/ignore-parser'; | ||
proxy?: string; | ||
targetUrl?: string; | ||
} | ||
@@ -19,0 +20,0 @@ export interface IApiCliConfig { |
@@ -50,27 +50,33 @@ "use strict"; | ||
async function TaskToStartConfig(task) { | ||
const parsedBaseUrl = url_1.default.parse(task.baseUrl); | ||
const randomPort = await get_port_1.default({ port: get_port_1.default.makeRange(3300, 3900) }); | ||
const serviceProtocol = parsedBaseUrl.protocol || 'http:'; | ||
const proxyPort = parsedBaseUrl.port || (serviceProtocol === 'http:' ? '80' : '443'); | ||
const parsedProxyBaseUrl = task.proxy && url_1.default.parse(task.proxy); | ||
const baseUrl = url_1.default.parse(task.baseUrl); | ||
const targetUrl = (task.targetUrl && url_1.default.parse(task.targetUrl)) || | ||
(task.proxy && url_1.default.parse(task.proxy)); // TODO: add deprecation warning | ||
const serviceProtocol = (targetUrl && targetUrl.protocol) || baseUrl.protocol || 'http:'; | ||
const serviceConfig = { | ||
host: (targetUrl && targetUrl.hostname) || baseUrl.hostname || 'localhost', | ||
protocol: serviceProtocol, | ||
port: targetUrl && targetUrl.port | ||
? parseInt(targetUrl.port) // use target port if available | ||
: targetUrl | ||
? serviceProtocol === 'http:' // assume standard ports for targets without explicit ports | ||
? 80 | ||
: 443 | ||
: await get_port_1.default({ port: get_port_1.default.makeRange(3300, 3900) }), | ||
basePath: (targetUrl && targetUrl.path) || baseUrl.path || '/', | ||
}; | ||
const proxyProtocol = baseUrl.protocol || 'http:'; | ||
const proxyConfig = { | ||
host: baseUrl.hostname || 'localhost', | ||
protocol: proxyProtocol, | ||
port: baseUrl.port | ||
? parseInt(baseUrl.port) // use base url port if explicitly set | ||
: proxyProtocol === 'http:' // assume standard port for base url without explicit port | ||
? 80 | ||
: 443, | ||
basePath: serviceConfig.basePath, | ||
}; | ||
return { | ||
command: task.command, | ||
serviceConfig: { | ||
port: task.proxy ? parseInt(proxyPort, 10) : randomPort, | ||
host: parsedBaseUrl.hostname || 'localhost', | ||
protocol: serviceProtocol, | ||
basePath: parsedBaseUrl.path || '/', | ||
}, | ||
proxyConfig: { | ||
port: parseInt(parsedProxyBaseUrl | ||
? parsedProxyBaseUrl.port || | ||
(serviceProtocol === 'http:' ? '80' : '443') | ||
: proxyPort, 10), | ||
host: (parsedProxyBaseUrl | ||
? parsedProxyBaseUrl.hostname | ||
: parsedBaseUrl.hostname) || 'localhost', | ||
protocol: (parsedProxyBaseUrl ? parsedProxyBaseUrl.protocol : serviceProtocol) || | ||
'http:', | ||
basePath: parsedBaseUrl.path || '/', | ||
}, | ||
serviceConfig, | ||
proxyConfig, | ||
}; | ||
@@ -77,0 +83,0 @@ } |
{ | ||
"name": "@useoptic/cli-config", | ||
"version": "8.1.1", | ||
"version": "8.2.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "ws:test": "echo config", |
Sorry, the diff of this file is not supported yet
15300
326