Skip to content

Commit

Permalink
Merge pull request #2126 from AdaptiveConsulting/fix/3162-service-wor…
Browse files Browse the repository at this point in the history
…ker-base-url

fix(serviceworker): service worker base url as origin for most cases
  • Loading branch information
algreasley authored Oct 26, 2022
2 parents cb4c3cb + af64464 commit 05f3458
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/client/src/Web/serviceWorkerRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This optional code is used to register a service worker.
// register() is not called by default.

import { ENVIRONMENT } from "@/constants"

// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
Expand Down Expand Up @@ -29,8 +31,10 @@ const doubleSlashesInURLRegex = /([^:])(\/{2,})/g
export function register(config?: Config) {
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
// This url can be changed back to using window.locationi.origin once we have fixed the env gateway url pathing
const swUrl = `${window.location.href}/sw.js`.replace(
// This url can be changed back to using window.location.origin once we have fixed the env gateway url pathing
const baseAddress =
ENVIRONMENT !== "env" ? window.location.origin : window.location.href
const swUrl = `${baseAddress}/sw.js`.replace(
doubleSlashesInURLRegex,
"$1/",
)
Expand Down

0 comments on commit 05f3458

Please sign in to comment.