Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(service-worker): change routing to allow redirect to login page #669

Merged
merged 4 commits into from
Oct 4, 2021

Conversation

KaiVandivier
Copy link
Contributor

@KaiVandivier KaiVandivier commented Oct 3, 2021

Addresses https://jira.dhis2.org/browse/LIBS-238

Can be tested like this:

  1. Build pwa package, adapter package, then the pwa-app
  2. Deploy to a live instance
  3. Visit /api/apps/pwa-app/ and /api/apps/pwa-app/index.html; verify app loads
  4. Visit /api/apps/pwa-app/hi and verify app loads (tests that subroutes are handled by index.html)
  5. At any of the any of the above urls, clear the session cookie and reload - verify the app redirects to the login page, and authenticating returns you to the url you left from
  6. Visit /api/apps/pwa-app//manifest.json to make sure you can visit static files

// a file extension, skip (unless it's index.html)
if (
fileExtensionRegexp.test(url.pathname) &&
!/index\.html$/.test(url.pathname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The (relatively) new String.prototype.endsWith would allow making the intention of this line a bit clearer:

Suggested change
!/index\.html$/.test(url.pathname)
!url.pathname.endsWith("index.html")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that 🙂

// Extract index.html from the manifest to precache, then route
// in a custom way
const indexHtmlManifestEntry = precacheManifest.find(({ url }) =>
url.includes('index.html')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be url.endsWith('index.html') too since this would match e.g. index.html.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah yeah, fair point 🙂

@KaiVandivier KaiVandivier enabled auto-merge (squash) October 4, 2021 11:10
@KaiVandivier KaiVandivier merged commit 97c84d4 into master Oct 4, 2021
@KaiVandivier KaiVandivier deleted the fix-routing-and-redirect branch October 4, 2021 11:12
dhis2-bot added a commit that referenced this pull request Oct 4, 2021
## [8.1.2](v8.1.1...v8.1.2) (2021-10-04)

### Bug Fixes

* **service-worker:** change routing to allow redirect to login page ([#669](#669)) ([97c84d4](97c84d4))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 8.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants