-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
42 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
export function getBaseUrl(domain: string) { | ||
function getUrl(domain: string, subdomain: string, path: string) { | ||
let url = domain | ||
const local = domain.startsWith('localhost') || domain.startsWith('127.0.0.') | ||
|
||
if (!domain.startsWith('http')) { | ||
const local = domain === 'localhost' || domain.startsWith('127.0.0.') | ||
url = `http${local ? '' : 's'}://${domain}` | ||
} | ||
|
||
const parsedUrl = new URL(url) | ||
|
||
return parsedUrl.toString() | ||
} | ||
|
||
export function getBillingUrl(domain: string) { | ||
let url = domain | ||
const local = domain === 'localhost' || domain.startsWith('127.0.0.') | ||
|
||
if (!domain.startsWith('http')) { | ||
url = `http${local ? '' : 's'}://${domain}` | ||
if (path) { | ||
const decodedUrl = decodeURIComponent(path) | ||
const [pathname, queryString] = decodedUrl.split('?') | ||
parsedUrl.pathname = pathname | ||
if (queryString) parsedUrl.search = queryString | ||
} | ||
|
||
const parsedUrl = new URL(url) | ||
if (!local) { | ||
parsedUrl.hostname = `billing.${parsedUrl.hostname}` | ||
parsedUrl.hostname = `${subdomain}.${parsedUrl.hostname}` | ||
} | ||
|
||
return parsedUrl.toString() | ||
} | ||
|
||
export function getAPIUrl(domain: string, path: string) { | ||
return getUrl(domain, 'api', path) | ||
} | ||
|
||
export function getBillingUrl(domain: string, path: string) { | ||
return getUrl(domain, 'billing', path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters