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
4 changes: 2 additions & 2 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const _ = require('lodash');
const merger = require('./config').merge;
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const {load} = require('js-yaml');

/**
* Docker and Compose version metadata.
Expand Down Expand Up @@ -110,7 +110,7 @@ const loadCacheFile = file => {
*/
const loadLandoFile = file => {
try {
return yaml.load(fs.readFileSync(file));
return load(fs.readFileSync(file, {encoding: 'utf-8'}));
} catch (e) {
throw new Error(`There was a problem with parsing ${file}. Ensure it is valid YAML! ${e}`, {cause: e});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const env = require('./env');
const fs = require('fs');
const path = require('path');
const os = require('os');
const yaml = require('js-yaml');
const {load} = require('js-yaml');
const url = require('url');

/**
Expand Down Expand Up @@ -223,7 +223,7 @@ exports.loadFiles = files => _(files)
})
// If the file is just a string lets map it to an object
.map(source => {
return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source)) || {}} : source;
return _.isString(source) ? {file: source, data: load(fs.readFileSync(source, 'utf-8')) || {}} : source;
})
// Add on the root directory for mapping purposes
.map(source => _.merge({}, source, {root: path.dirname(source.file)}))
Expand Down
6 changes: 3 additions & 3 deletions lib/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const fs = require('fs');
const Log = require('./logger');
const path = require('path');
const yaml = require('js-yaml');
const {dump, load} = require('js-yaml');

/**
* YAML helper for reading and writing config files.
Expand All @@ -30,7 +30,7 @@ module.exports = class Yaml {
*/
load(file) {
try {
return yaml.load(fs.readFileSync(file));
return load(fs.readFileSync(file, {encoding: 'utf-8'}));
} catch (e) {
this.log.error('Problem parsing %s with %s', file, e.message);
}
Expand All @@ -50,7 +50,7 @@ module.exports = class Yaml {
// Remove any properties that might be bad and dump
data = JSON.parse(JSON.stringify(data));
// And dump
fs.writeFileSync(file, yaml.dump(data));
fs.writeFileSync(file, dump(data));
// Log and return filename
return file;
};
Expand Down
33 changes: 28 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"copy-dir": "^1.3.0",
"dockerode": "^5.0.1",
"glob": "^13.0.0",
"js-yaml": "^4.3.0",
"js-yaml": "^5.4.1",
"jsonfile": "^6.2.1",
"lodash": "^4.18.1",
"node-cache": "^5.1.2",
Expand Down
20 changes: 16 additions & 4 deletions plugins/lando-proxy/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,28 @@ exports.parseUrl = data => {
// 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.
const parsedUrl = _.isString(data) ? url.parse(`http://${data}`.replace(/\*/g, '__wildcard__')) : _.merge({}, data, {
hostname: data.hostname.replace(/\*/g, '__wildcard__'),
});
let parsedUrl;
if (typeof data === 'string') {
const u = new URL(`http://${data}`);
parsedUrl = {...url.urlToHttpOptions(u)};
['port', 'hash', 'search'].forEach(prop => {
parsedUrl[prop] ||= null;
});
parsedUrl.query = u.searchParams.toString();
if (parsedUrl.port) {
parsedUrl.port = parsedUrl.port.toString();
}
parsedUrl.host = u.host;
} else {
parsedUrl = {...data};
}

// If the port is null then set it to 80
if (_.isNil(parsedUrl.port)) parsedUrl.port = '80';

// Retranslate and send
const defaults = {port: '80', pathname: '/', middlewares: []};
return _.merge(defaults, parsedUrl, {host: parsedUrl.hostname.replace(/__wildcard__/g, '*')});
return _.merge(defaults, parsedUrl, {host: parsedUrl});
};

/**
Expand Down
Loading