Skip to content

Commit ce50431

Browse files
committed
Changed UrlUtils to replace protocol to be in line with the one specified in the CDN
1 parent 9ac41f4 commit ce50431

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/providers/generic/connection/CdnProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class CdnProvider {
5858

5959
public static replaceCdnHost(url: string) {
6060
return CdnProvider.preferredCdn
61-
? replaceHost(url, CdnProvider.preferredCdn.host)
61+
? replaceHost(url, CdnProvider.preferredCdn)
6262
: url;
6363
}
6464

src/utils/UrlUtils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CdnDefinition } from 'src/providers/cdn/CdnHostList';
2+
13
/**
24
* Append given search parameters to an URL which may or may not already
35
* have search parameters.
@@ -21,13 +23,14 @@ export const addOrReplaceSearchParams = (url: string, paramString: string) => {
2123
* Replace URL host, i.e. the domain and the port number.
2224
*
2325
* @param url e.g. "https://thunderstore.io/foo"
24-
* @param domainAndPort e.g. "thunderstore.dev" or "thunderstore.dev:8080"
26+
* @param cdn The preferred cdn definition
2527
* @returns e.g. "https://thunderstore.dev:8080/foo"
2628
*/
27-
export const replaceHost = (url: string, domainAndPort: string) => {
28-
const newValues = domainAndPort.split(":");
29+
export const replaceHost = (url: string, cdn: CdnDefinition) => {
30+
const newValues = cdn.host.split(":");
2931
const newUrl = new URL(url);
30-
newUrl.hostname = newValues[0];
32+
newUrl.hostname = newValues[0]!;
3133
newUrl.port = newValues[1] || "";
34+
newUrl.protocol = cdn.protocol;
3235
return newUrl.href;
3336
};

0 commit comments

Comments
 (0)