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

Service Worker Scope Issue with Backend Admin Access in Vite PWA Plugin #764

Open
mustermannalex opened this issue Oct 6, 2024 · 1 comment

Comments

@mustermannalex
Copy link

mustermannalex commented Oct 6, 2024

I’m working on a project where I have a backend with an admin area that is accessible under a specific URL path, let’s call it the Backend-Prefix. I also have a frontend built with Vite that includes a Service Worker generated by the Vite PWA Plugin.

Here’s the issue:
When the Service Worker is active, I cannot access the backend’s admin area. The Service Worker seems to block the request to the admin URL, possibly because it doesn’t recognize it, and therefore does not proxy the request correctly to the backend. As a result, I only see a blank page.
What I’ve Tried:

If I manually modify the Service Worker’s scope in the registration script, setting it to cover only the App-Prefix (i.e., /app/), it works fine. The Service Worker no longer interferes with the backend admin, and I can access the admin panel as expected.

However, my problem is that the Vite PWA Plugin automatically regenerates the Service Worker when building the project, and I want to avoid manually modifying the scope every time I build the project. I need a more automated or persistent way to configure the Service Worker to handle the scope correctly without manual intervention after each build.
My Current Setup:

Frontend: Vite with Vite PWA Plugin
Backend: Django (with an admin area under /api/admin/)
The frontend and backend are served under different prefixes (App-Prefix and Backend-Prefix).

Any ideas or best practices on how to configure the Service Worker for this setup would be much appreciated!

@userquin
Copy link
Member

userquin commented Oct 6, 2024

Try adding scope: '/app/' to the pwa options. If I understand you correctly, you've 2 apps served under /app/ and /admin-app/ (or root /) contexts.

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

No branches or pull requests

2 participants