Fix URL generation for subdir deployments

We discovered that the build process strips trailing slashes
from PUBLIC_URL, which thwarted our plans in getHomepageUrl.
This ensures the function always returns a trailing slash.

Change-Id: I03c4ec79ee4566a8b7fbd4e04c18e86f4257fa8f
This commit is contained in:
James E. Blair 2023-07-26 07:04:50 -07:00
parent 633b63b50f
commit 95814f7734
2 changed files with 6 additions and 2 deletions

View File

@ -40,7 +40,9 @@ function getHomepageUrl() {
} else {
url.pathname = ''
}
if (!url.pathname.endsWith('/')) {
url.pathname = url.pathname + '/'
}
return url.origin + url.pathname
}

View File

@ -36,8 +36,10 @@ it('should return the subdir homepage url', () => {
Object.defineProperty(window, 'location', {
value: new URL(homepage)
} )
// The build process strips trailing slashes from PUBLIC_URL,
// so make sure we don't include any in our tests
Object.defineProperty(process.env, 'PUBLIC_URL', {
value: '/zuul/'
value: '/zuul'
} )
// Test some of the known, possible, URLs to verify