Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion builders/_drupaly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Modules
const _ = require('lodash');
const path = require('path');
const urlUtility = require('url');

/*
* Helper to get a phar download and setupcommand
Expand Down Expand Up @@ -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 = <empty>
// - 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;
};