Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const host = new URL(window.location.href)
function getDashboardReloadUrl () {
const setupBasePath = store.state.setup.setup?.basePath
const currentDashboardPath = window.location.pathname.match(/^(.+?\/dashboard)(?:\/|$)/)?.[1]
const basePath = setupBasePath || currentDashboardPath || '/dashboard'
const rawBasePath = setupBasePath || currentDashboardPath || '/dashboard'
const basePath = rawBasePath.endsWith('/') ? rawBasePath : rawBasePath + '/'

return new URL(basePath, window.location.origin)
}
Expand Down
37 changes: 15 additions & 22 deletions ui/src/sw.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
/// <reference lib="webworker" />
import { clientsClaim } from 'workbox-core'
import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching'
import { cleanupOutdatedCaches, matchPrecache, precacheAndRoute } from 'workbox-precaching'
import { NavigationRoute, registerRoute } from 'workbox-routing'
import { NetworkOnly } from 'workbox-strategies'

// Network-first (keeps 'navigate' mode so an auth proxy's login redirect is followed), cached shell
// on failure. Registered before the precache route so it owns every navigation.
registerRoute(new NavigationRoute(new NetworkOnly({
networkTimeoutSeconds: 5,
plugins: [{
// 5xx -> serve the shell so it can self-heal. Match >= 500 not !response.ok, so the
// status-0 opaqueredirect (the auth redirect) passes through.
fetchDidSucceed: async ({ response }) =>
response.status >= 500 ? (await matchPrecache('index.html')) || response : response,
handlerDidError: async () => (await matchPrecache('index.html')) || Response.error()
}]
})))

// self.__WB_MANIFEST is the default injection point
precacheAndRoute(self.__WB_MANIFEST)

// clean old assets
cleanupOutdatedCaches()

/** @type {RegExp[] | undefined} */
const denylist = []

// in dev mode, do not precache anything
if (import.meta.env.DEV) {
// don't precache anything
console.log('Development mode, not pre-caching anything')
denylist.push(/.*/)
} else {
// don't precache anything where the urls pathname ends with a slash (including times when the url has a query string)
// this permits the request to be handled by the server which will do a redirect as required
const configPath = self.location.pathname.split('/')[1]
denylist.push(new RegExp(`/${configPath}/[^?]*/(\\?.*)*$`))
}

// to allow work offline for allowed routes only
registerRoute(new NavigationRoute(
createHandlerBoundToURL('index.html'),
{ denylist }
))

self.skipWaiting()
// https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim
clientsClaim()
Expand Down
10 changes: 5 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VitePWA } from 'vite-plugin-pwa'
*/

// https://vitejs.dev/config/
export default defineConfig({
export default defineConfig(({ mode }) => ({
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js'
Expand All @@ -31,8 +31,8 @@ export default defineConfig({
manifest: false,

injectManifest: {
maximumFileSizeToCacheInBytes: process.env.NODE_ENV === 'development' ? 6000000 : 3350000,
globPatterns: ['**/*.{js,css,html,svg,png,ico,ttf,eot,woff,woff2}']
maximumFileSizeToCacheInBytes: mode === 'development' ? 6000000 : 3350000,
globPatterns: mode === 'development' ? [] : ['**/*.{js,css,html,svg,png,ico,ttf,eot,woff,woff2}']
},

devOptions: {
Expand All @@ -45,7 +45,7 @@ export default defineConfig({
],
root: 'ui',
build: {
minify: process.env.NODE_ENV === 'development' ? false : undefined,
minify: mode === 'development' ? false : undefined,
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
Expand All @@ -60,4 +60,4 @@ export default defineConfig({
}
},
base: './'
})
}))
Loading