From 5eeaf42e4d1d907085bfd7b046daafbb1e58472c Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 30 Apr 2022 15:09:30 -0500 Subject: [PATCH] Try PUBLIC_URL first --- helpers/get-site-url.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/helpers/get-site-url.js b/helpers/get-site-url.js index e416979..e85a4fc 100644 --- a/helpers/get-site-url.js +++ b/helpers/get-site-url.js @@ -5,6 +5,18 @@ export function getSiteUrl () { const hasImportMeta = typeof import.meta !== 'undefined' const hasImportMetaEnv = hasImportMeta && typeof import.meta.env !== 'undefined' + // Try PUBLIC_URL + if ( typeof process.env.PUBLIC_URL !== 'undefined' ) { + console.log('Has env.PUBLIC_URL') + return process.env.PUBLIC_URL + } + + if ( hasImportMetaEnv && typeof import.meta.env.PUBLIC_URL !== 'undefined' ) { + console.log('Has PUBLIC_URL') + return import.meta.env.PUBLIC_URL + } + + // Try process.env.URL if ( typeof process.env.URL !== 'undefined' ) { console.log('Has env.URL') @@ -23,11 +35,5 @@ export function getSiteUrl () { return import.meta.env.URL } - // Try PUBLIC_URL - if ( hasImportMetaEnv && typeof import.meta.env.PUBLIC_URL !== 'undefined' ) { - console.log('Has PUBLIC_URL') - return import.meta.env.PUBLIC_URL - } - throw new Error('Could not find site URL') }