diff --git a/helpers/url.js b/helpers/url.js index 1c6ee01..e026426 100644 --- a/helpers/url.js +++ b/helpers/url.js @@ -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')