mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add getApiUrl helper
This commit is contained in:
parent
ef065423cc
commit
d96332730d
1 changed files with 20 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
export function getSiteUrl () {
|
||||
|
||||
// console.log( 'import.meta.site', import.meta.env )
|
||||
|
|
@ -38,6 +39,25 @@ export function getSiteUrl () {
|
|||
throw new Error('Could not find site URL')
|
||||
}
|
||||
|
||||
export function getApiUrl () {
|
||||
|
||||
const hasImportMeta = typeof import.meta !== 'undefined'
|
||||
const hasImportMetaEnv = hasImportMeta && typeof import.meta.env !== 'undefined'
|
||||
|
||||
// Try PUBLIC_API_DOMAIN
|
||||
if ( typeof process.env.PUBLIC_API_DOMAIN !== 'undefined' ) {
|
||||
// console.log('Has env.PUBLIC_API_DOMAIN')
|
||||
return process.env.PUBLIC_API_DOMAIN
|
||||
}
|
||||
|
||||
if ( hasImportMetaEnv && typeof import.meta.env.PUBLIC_API_DOMAIN !== 'undefined' ) {
|
||||
// console.log('Has PUBLIC_API_DOMAIN')
|
||||
return import.meta.env.PUBLIC_API_DOMAIN
|
||||
}
|
||||
|
||||
throw new Error('Could not find API URL')
|
||||
}
|
||||
|
||||
export function getPartPartsFromUrl ( urlString ) {
|
||||
if ( typeof urlString !== 'string' ) throw new Error('urlString must be a string')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue