Skip to content

Commit

Permalink
fix(MongoBinaryUrl): getDownloadUrl: try to create an "URL" to check …
Browse files Browse the repository at this point in the history
…if the url is valid
  • Loading branch information
hasezoey committed Mar 14, 2021
1 parent 3ae6a45 commit 25c865c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/api/config-options.md
Expand Up @@ -49,7 +49,7 @@ Option `DEBUG` is used to enable Debug Output

Option `DOWNLOAD_MIRROR` is used to set which mirror to use

Default / Format: `https://fastdl.mongodb.org`
Default / Format: `https://fastdl.mongodb.org` (protocol needs to be included)

### DOWNLOAD_URL

Expand Down
Expand Up @@ -4,6 +4,7 @@ import debug from 'debug';
import * as semver from 'semver';
import { isNullOrUndefined } from './utils';
import { BaseDryMongoBinaryOptions, DryMongoBinary } from './DryMongoBinary';
import { URL } from 'url';

const log = debug('MongoMS:MongoBinaryDownloadUrl');

Expand Down Expand Up @@ -39,7 +40,9 @@ export class MongoBinaryDownloadUrl {
if (downloadUrl) {
log(`Using "${downloadUrl}" as the Download-URL`);

return downloadUrl;
const url = new URL(downloadUrl); // check if this is an valid url

return url.toString();
}

const archive = await this.getArchiveName();
Expand All @@ -49,7 +52,10 @@ export class MongoBinaryDownloadUrl {
resolveConfig(ResolveConfigVariables.DOWNLOAD_MIRROR) ?? 'https://fastdl.mongodb.org';
log(`Using "${mirror}" as the mirror`);

return `${mirror}/${this.platform}/${archive}`;
const url = new URL(mirror);
url.pathname = `/${this.platform}/${archive}`;

return url.toString();
}

/**
Expand Down

0 comments on commit 25c865c

Please sign in to comment.