Add PUBLIC_URL to vite config
The use of PUBLIC_URL was removed from the index file because it appeared that we could use a relative url base for subdir hosting, however, that relative url doesn't work with deep links so we had to revert back to an absolute url in the index file. However, in order to support subdir hosting with an absolute url in the index, we need to make it configurable. This adds back the use of PUBLIC_URL in the index by using it in the vite config to set the base URL. Also update the docs to reflect the current steps needed for subdir deployment. Change-Id: I9b186b85ebe188160e2ee0ee7c697155c2b2f282
This commit is contained in:
1 parent
a2ae9cca74
commit
a9b728b2b1
4 files changed
+30
-33
No files matched your search
@@ -153,10 +153,10 @@ application as the document root and add rewrite rules::
|
||||
Sub directory serving
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The web application needs to be rebuilt to update the internal location of
|
||||
the static files. Set the homepage setting in the package.json to an
|
||||
absolute path or url. For example, to deploy the web interface through a
|
||||
'/zuul/' sub directory:
|
||||
The web application needs to be rebuilt to update the internal
|
||||
location of the static files. Set the environment variable
|
||||
`PUBLIC_URL` to an absolute path when building. For example, to deploy
|
||||
the web interface through a `/zuul` sub directory:
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -166,8 +166,7 @@ absolute path or url. For example, to deploy the web interface through a
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sed -e 's#"homepage": "/"#"homepage": "/zuul/"#' -i package.json
|
||||
yarn build
|
||||
PUBLIC_URL=/zuul yarn build
|
||||
|
||||
Then assuming the web application is unpacked in /usr/share/zuul,
|
||||
enable the ``mod_rewrite`` Apache module and add the following rewrite
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ function getHomepageUrl() {
|
||||
//
|
||||
let url = new URL(window.location.href)
|
||||
|
||||
if ('PUBLIC_URL' in import.meta.env) {
|
||||
url.pathname = import.meta.env.PUBLIC_URL
|
||||
if ('BASE_URL' in import.meta.env) {
|
||||
url.pathname = import.meta.env.BASE_URL
|
||||
} else {
|
||||
url.pathname = ''
|
||||
}
|
||||
|
||||
+22
-24
@@ -40,33 +40,31 @@ it('should should return the homepage url', () => {
|
||||
})
|
||||
|
||||
it('should return the subdir homepage url', () => {
|
||||
const homepage = 'https://example.com/zuul/'
|
||||
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
|
||||
vi.stubEnv('PUBLIC_URL', '/zuul')
|
||||
const homepage = 'https://example.com/zuul/'
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: new URL(homepage)
|
||||
})
|
||||
vi.stubEnv('BASE_URL', '/zuul')
|
||||
|
||||
// Test some of the known, possible, URLs to verify
|
||||
// that the origin is returned.
|
||||
const urls = [
|
||||
// auth_callback test as some providers build
|
||||
// different callback urls
|
||||
'https://example.com/zuul/auth_callback',
|
||||
'https://example.com/zuul/auth_callback#state=12345',
|
||||
// Test some of the known, possible, URLs to verify
|
||||
// that the origin is returned.
|
||||
const urls = [
|
||||
// auth_callback test as some providers build
|
||||
// different callback urls
|
||||
'https://example.com/zuul/auth_callback',
|
||||
'https://example.com/zuul/auth_callback#state=12345',
|
||||
|
||||
// Regular browser navigation urls
|
||||
'https://example.com/zuul/status',
|
||||
'https://example.com/zuul/t/zuul-tenant/status',
|
||||
'https://example.com/zuul/t/zuul-tenant/jobs',
|
||||
]
|
||||
// Regular browser navigation urls
|
||||
'https://example.com/zuul/status',
|
||||
'https://example.com/zuul/t/zuul-tenant/status',
|
||||
'https://example.com/zuul/t/zuul-tenant/jobs',
|
||||
]
|
||||
|
||||
for (let url of urls) {
|
||||
window.location.href = url
|
||||
expect(getHomepageUrl()).toEqual(homepage)
|
||||
}
|
||||
})
|
||||
for (let url of urls) {
|
||||
window.location.href = url
|
||||
expect(getHomepageUrl()).toEqual(homepage)
|
||||
}
|
||||
})
|
||||
|
||||
it('should not request logs with auth header per default', () => {
|
||||
vi.stubEnv('REACT_APP_ZUUL_API', 'https://example.com/api/')
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import path from 'path';
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ mode }) => {
|
||||
return {
|
||||
base: '/',
|
||||
base: process.env.PUBLIC_URL ? process.env.PUBLIC_URL : '/',
|
||||
envPrefix: 'REACT_APP',
|
||||
test: {
|
||||
globals: true,
|
||||
|
||||
Reference in new issue
Block a user