chore(web): memoize default url since it'll mostly always be the same no matter what

This commit is contained in:
41666 2021-03-13 05:16:25 -05:00
parent a87ccd9c54
commit fac361d277
3 changed files with 23 additions and 13 deletions

View file

@ -19,6 +19,7 @@
"@types/node": "^14.14.33",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"memoize-one": "^5.1.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-helmet": "^6.1.0",

View file

@ -1,14 +1,18 @@
export const getDefaultApiUrl = (host: string = window.location.hostname) => {
if (/^roleypoly.com$/.test(host)) {
return 'https://api-prod.roleypoly.com';
} else if (
/roleypoly\.pages\.dev$/.test(host) ||
/^stage.roleypoly.com$/.test(host)
) {
return 'https://api-stage.roleypoly.com';
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
return 'http://localhost:6609';
} else {
return 'https://api-prod.roleypoly.com';
import * as memoizeOne from 'memoize-one';
export const getDefaultApiUrl = memoizeOne.default(
(host: string = window.location.hostname) => {
if (/^roleypoly.com$/.test(host)) {
return 'https://api-prod.roleypoly.com';
} else if (
/roleypoly\.pages\.dev$/.test(host) ||
/^stage.roleypoly.com$/.test(host)
) {
return 'https://api-stage.roleypoly.com';
} else if (/\blocalhost|127\.0\.0\.1\b/.test(host)) {
return 'http://localhost:6609';
} else {
return 'https://api-prod.roleypoly.com';
}
}
};
);