diff --git a/builders/_drupaly.js b/builders/_drupaly.js index ca5da06..8e9c3d8 100644 --- a/builders/_drupaly.js +++ b/builders/_drupaly.js @@ -294,7 +294,8 @@ module.exports = { // Set DRUSH_OPTIONS_URI based on drush_uri config or proxy settings let drushUri = options.drush_uri; if (!drushUri) { - const proxyUrl = options.proxy[options.proxyService]?.[0]; + // Get hostname only, in-case of added port number. + const proxyUrl = utils.getProxyHostname(options.proxy[options.proxyService]?.[0]); if (proxyUrl) { // Check SSL setting for the proxy service const proxyServiceSsl = options.services[options.proxyService]?.ssl; diff --git a/lib/utils.js b/lib/utils.js index 6eaf031..4c24e92 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,6 +3,7 @@ // Modules const _ = require('lodash'); const path = require('path'); +const urlUtility = require('url'); /* * Helper to get a phar download and setupcommand @@ -85,3 +86,32 @@ exports.parseConfig = (recipe, app) => _.merge({}, _.get(app, 'config.config', { root: app.root, userConfRoot: app._config.userConfRoot, }); + +/* + * Helper to get Proxy hostname. + */ +exports.getProxyHostname = (proxyUrlString = '') => { + // Change format `[hostname][:port]` into `[protocol://][hostname][:port] + // Otherwise, it shows bad parsing. + // - Port = hostname + // - Hostname = + // - Pathname = hostname + + // @todo Can we expose this function upstream and reuse it? + // @see https://github.com/lando/core/blob/main/utils/parse-proxy-url.js + // E.g. options._app._lando.parseProxyUrl(). + + // We add the protocol ourselves, so it can be parsed. We also change all * + // occurrences for our magic word __wildcard__, because otherwise the url parser + // won't parse wildcards in the hostname correctly. + if (_.isString(proxyUrlString)) { + try { + const urlObject = urlUtility.parse(`http://${proxyUrlString}`.replace(/\*/g, '__wildcard__')); + return urlObject.hostname; + } + catch (error) { + return undefined; + } + } + return undefined; +};