Skip to content

Commit

Permalink
feat(api/utils): create getBaseUrl method
Browse files Browse the repository at this point in the history
  • Loading branch information
JowiAoun committed Sep 28, 2024
1 parent d7a80bb commit e3e54e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './lib/utils'

export * from './url'
13 changes: 13 additions & 0 deletions libs/utils/src/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import process from 'node:process'

/**
* 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(process.env.PORT ?? 3000)}`
}

0 comments on commit e3e54e8

Please sign in to comment.