From 02b8980f45b7b327d9e9bc46f7d1a0aec64e4adf Mon Sep 17 00:00:00 2001 From: jowi Date: Sat, 28 Sep 2024 00:45:04 -0400 Subject: [PATCH] feat(api/utils): create getBaseUrl method --- libs/utils/src/index.ts | 2 ++ libs/utils/src/url.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 libs/utils/src/url.ts diff --git a/libs/utils/src/index.ts b/libs/utils/src/index.ts index 842d335e..faae9145 100644 --- a/libs/utils/src/index.ts +++ b/libs/utils/src/index.ts @@ -1 +1,3 @@ export * from './lib/utils' + +export * from './url' diff --git a/libs/utils/src/url.ts b/libs/utils/src/url.ts new file mode 100644 index 00000000..9ea9d088 --- /dev/null +++ b/libs/utils/src/url.ts @@ -0,0 +1,11 @@ +/** + * This function gets the base URL of the current environment. + * @returns The base URL. + */ +export function getBaseUrl() { + if (typeof window !== 'undefined') { + return window.location.origin + } + + return `http://localhost:${String(3000)}` +}