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

Feature request: ngsw navigation path exceptions #20404

Closed
kernwig opened this issue Nov 13, 2017 · 6 comments
Closed

Feature request: ngsw navigation path exceptions #20404

kernwig opened this issue Nov 13, 2017 · 6 comments
Labels
area: service-worker Issues related to the @angular/service-worker package feature Issue that requests a new feature freq2: medium
Milestone

Comments

@kernwig
Copy link

kernwig commented Nov 13, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The service worker isNavigationRequest() function assumes that any page navigation within scope is to be handled by the service worker. There are cases were this is not desired behavior.

Expected behavior

Provide a means of configuring exception paths that are checked in isNavigationRequest().

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Example need: Hosting server services and authentication via Feathers.js expects to navigate to the path /auth/google to initiate an OAUTH2 authentication via Google; with completion of authentication directing back to /auth/google/callback. These requests must go through to the server. Currently ngsw-worker.js intercepts these requests and return the start page HTML.

Environment


Angular version: 5.0.1


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 7.10.1
- Platform:  Mac

Others:

@kernwig
Copy link
Author

kernwig commented Nov 13, 2017

Stream of comments on Slack as I dealt with this problem:

Adam Fanello [4:34 PM]
Any help out there? I upgraded my app to Angular 5 with @anguler/service-worker, and it all worked on my computer. Upon deploying though, the server worker is intercepting the authentication request to the server and responding with my index.html!?!
Authentication goes to /auth/google or /auth/facebook. Nowhere in https://sqac.fanello.net/ngsw.json is any /auth path mentioned, yet Chrome's network tab shows the index.html content being returned by the service worker. It behaves correctly if I stop the SW.

Adam Fanello [8:14 PM]
If anyone is out there.. found the problem has to do with scope. The service-worker thinks it needs to control any page navigation under it, but login requires network access to hit the OAUTH server endpoint and be redirected to the OAUTH provider. Trying to figure out how to work around this. (Doesn't happen in dev because client and server are coming from two different ports in dev.) (edited)

Adam Fanello [8:51 PM]
I don't know why, but ngsw-worker.js includes an exception when navigating to a URL containing two underscores. I added #__ to the end of each URL (ex: /auth/google#__), and that fixed the problem. Quite the PWA gotcha that I haven't seen mentioned anywhere.

Adam Fanello [9:42 PM]
Ugh! Again dev and prod don't behave the same. OAUTH callback doesn't have the double-underscore, so fail. This is such a hack. Basically ngsw is designed not to allow the client code and server API to reside on the same domain! (edited)

Adam Fanello [10:42 PM]
Finally found all the places to add __ to every API path. (OAUTH was tricky.) Working, but what a hack! 😕

@jasonaden jasonaden added the area: service-worker Issues related to the @angular/service-worker package label Nov 13, 2017
@alxhub alxhub added freq1: low severity2: inconvenient feature Issue that requests a new feature labels Nov 29, 2017
@alxhub alxhub added this to Backlog in Service Worker Dec 7, 2017
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@gkalpak
Copy link
Member

gkalpak commented Mar 20, 2018

We also need this for angular.io. The usecase:
We want some requests to pass through to the server, were we have configured certain redirection rules. With the previous @angular/service-worker, we were able to exclude specific requests (based on the URL) from being handled by the SW, so these URLs were passed through to the server.

cc @IgorMinar, @alxhub

@alxhub
Copy link
Member

alxhub commented Mar 21, 2018

@gkalpak this is a feature that was omitted from the new SW in the hopes that navigation-detection would prove sufficient. I think the current blacklist approach which detects URLs with __ or file extensions should be expanded into a a configurable list of URL glob patterns which are excluded.

gkalpak added a commit to gkalpak/angular that referenced this issue Mar 27, 2018
Normally, the ServiceWorker will redirect navigation requests that don't
match any `asset` or `data` group to the specified index file. Yet,
sometimes it is desirable to configure the SW to ignore specific URLs
(even for navigation requests) and pass them through to the server.

This commit adds support for specifying an optional `ignoredUrlPatterns`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `*` and `**`). Requests matching these URLs
or patterns will not be handled by the SW.

Fixes angular#20404
gkalpak added a commit to gkalpak/angular that referenced this issue Mar 28, 2018
Normally, the ServiceWorker will redirect navigation requests that don't
match any `asset` or `data` group to the specified index file. Yet,
sometimes it is desirable to configure the SW to ignore specific URLs
(even for navigation requests) and pass them through to the server.

This commit adds support for specifying an optional `ignoredUrlPatterns`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `*` and `**`). Requests matching these URLs
or patterns will not be handled by the SW.

Fixes angular#20404
@coryrylan
Copy link
Contributor

Would a list of regexes be more flexible?
Workbox has a navigateFallbackWhitelist and navigateFallbackBlacklist properies to take a list of regexes to scope the service worker to. This is actually the feature that is keeping us on Workbox instead of migrating to @angular/service-worker. We use navigateFallbackWhitelist to only apply to the angular specific pages as we are converting a large enterprise app.

https://developers.google.com/web/tools/workbox/modules/workbox-build

@gkalpak
Copy link
Member

gkalpak commented Mar 30, 2018

Let's discuss on #23025.

gkalpak added a commit to gkalpak/angular that referenced this issue Apr 12, 2018
Normally, the ServiceWorker will redirect navigation requests that don't
match any `asset` or `data` group to the specified index file. Yet,
sometimes it is desirable to configure the SW to ignore specific URLs
(even for navigation requests) and pass them through to the server.

This commit adds support for specifying an optional `ignoredUrlPatterns`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `*` and `**`). Requests matching these URLs
or patterns will not be handled by the SW.

Fixes angular#20404
gkalpak added a commit to gkalpak/angular that referenced this issue Apr 12, 2018
The ServiceWorker will redirect navigation requests that don't match any
`asset` or `data` group to the specified index file. The rules for a
request to be classified as a navigation request are as follows:
1. Its `mode` must be `navigation`.
2. It must accept a `text/html` response.
3. Its URL must match certain criteria (see below).

By default, a navigation request can have any URL except for:
1. URLs containing `__`.
2. URLs to files (i.e. containing a file extension in the last path
   segment).

While thse rules are fine in many cases, sometimes it is desirable to
configure different rules for the URLs of navigation requests (e.g.
ignore specific URLs and pass them through to the server).

This commit adds support for specifying an optional `navigationUrls`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `!`, `*` and `**`).
Only requests whose URLs match any of the positive URLs/patterns and
none of the negative ones (i.e. URLs/patterns starting with `!`) will be
considered navigation requests (and handled accordingly by the SW).

(This is an alternative implementation to angular#23025.)

Fixes angular#20404
gkalpak added a commit to gkalpak/angular that referenced this issue Apr 12, 2018
The ServiceWorker will redirect navigation requests that don't match any
`asset` or `data` group to the specified index file. The rules for a
request to be classified as a navigation request are as follows:
1. Its `mode` must be `navigation`.
2. It must accept a `text/html` response.
3. Its URL must match certain criteria (see below).

By default, a navigation request can have any URL except for:
1. URLs containing `__`.
2. URLs to files (i.e. containing a file extension in the last path
   segment).

While thse rules are fine in many cases, sometimes it is desirable to
configure different rules for the URLs of navigation requests (e.g.
ignore specific URLs and pass them through to the server).

This commit adds support for specifying an optional `navigationUrls`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `!`, `*` and `**`).
Only requests whose URLs match any of the positive URLs/patterns and
none of the negative ones (i.e. URLs/patterns starting with `!`) will be
considered navigation requests (and handled accordingly by the SW).

(This is an alternative implementation to angular#23025.)

Fixes angular#20404
gkalpak added a commit to gkalpak/angular that referenced this issue Apr 12, 2018
The ServiceWorker will redirect navigation requests that don't match any
`asset` or `data` group to the specified index file. The rules for a
request to be classified as a navigation request are as follows:
1. Its `mode` must be `navigation`.
2. It must accept a `text/html` response.
3. Its URL must match certain criteria (see below).

By default, a navigation request can have any URL except for:
1. URLs containing `__`.
2. URLs to files (i.e. containing a file extension in the last path
   segment).

While these rules are fine in many cases, sometimes it is desirable to
configure different rules for the URLs of navigation requests (e.g.
ignore specific URLs and pass them through to the server).

This commit adds support for specifying an optional `navigationUrls`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `!`, `*` and `**`).
Only requests whose URLs match any of the positive URLs/patterns and
none of the negative ones (i.e. URLs/patterns starting with `!`) will be
considered navigation requests (and handled accordingly by the SW).

(This is an alternative implementation to angular#23025.)

Fixes angular#20404
gkalpak added a commit to gkalpak/angular that referenced this issue Apr 12, 2018
The ServiceWorker will redirect navigation requests that don't match any
`asset` or `data` group to the specified index file. The rules for a
request to be classified as a navigation request are as follows:
1. Its `mode` must be `navigation`.
2. It must accept a `text/html` response.
3. Its URL must match certain criteria (see below).

By default, a navigation request can have any URL except for:
1. URLs containing `__`.
2. URLs to files (i.e. containing a file extension in the last path
   segment).

While these rules are fine in many cases, sometimes it is desirable to
configure different rules for the URLs of navigation requests (e.g.
ignore specific URLs and pass them through to the server).

This commit adds support for specifying an optional `navigationUrls`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `!`, `*` and `**`).
Only requests whose URLs match any of the positive URLs/patterns and
none of the negative ones (i.e. URLs/patterns starting with `!`) will be
considered navigation requests (and handled accordingly by the SW).

(This is an alternative implementation to angular#23025.)

Fixes angular#20404
Service Worker automation moved this from Backlog to Done Apr 13, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: service-worker Issues related to the @angular/service-worker package feature Issue that requests a new feature freq2: medium
Projects
No open projects
6 participants
@jasonaden @coryrylan @alxhub @gkalpak @kernwig and others