-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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): fix handling absolute and relative base href #37922
Conversation
You can preview 17b9d4b at https://pr37922-17b9d4b.ngbuilds.io/. |
You can preview 63974dd at https://pr37922-63974dd.ngbuilds.io/. |
You can preview 3953c4a at https://pr37922-3953c4a.ngbuilds.io/. |
You can preview 4d3843f at https://pr37922-4d3843f.ngbuilds.io/. |
You can preview e574fbb at https://pr37922-e574fbb.ngbuilds.io/. |
58f4704
to
407f8ff
Compare
You can preview 407f8ff at https://pr37922-407f8ff.ngbuilds.io/. |
…scope The Angular ServiceWorker can serve requests to a special virtual path, `ngsw/state`, showing [information about its internal state][1], which can be useful for debugging. Previously, this would only work if the ServiceWorker's [scope][2] was the root directory (`/`). Otherwise, (e.g. when building the app with `--baseHref=/some/path/`), the ServiceWorker would fail to detect a request to `/some/path/ngsw/state` as matching `ngsw/state` and would not serve it with the debugging information. This commit fixes it by ensuring that the ServiceWorker's scope is taken into account when detecting a request to `ngsw/state`. [1]: https://angular.io/guide/service-worker-devops#locating-and-analyzing-debugging-information [2]: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/scope Fixes angular#30505
This is in preparation of enabling the ServiceWorker to handle relative paths in `ngsw.json` (as discussed in angular#25055), which will require normalizing URLs in other parts of the ServiceWorker.
…l ones This commit makes the mock implementations used is ServiceWorker tests behave more similar to the actual ones.
You can preview 6eb027c at https://pr37922-6eb027c.ngbuilds.io/. |
In some cases, it is useful to use a relative base href in the app (e.g. when an app has to be accessible on different URLs, such as on an intranet and the internet - see angular#25055 for a related discussion). Previously, the Angular ServiceWorker was not able to handle relative base hrefs (for example when building the with `--base-href=./`). This commit fixes this by normalizing all URLs from the ServiceWorker configuration wrt the ServiceWorker's scope. Fixes angular#25055
Some ServiceWorker operations and methods require normalized URLs. Previously, the generic `string` type was used. This commit introduces a new `NormalizedUrl` type, a special kind of `string`, to make this requirement explicit and use the type system to enforce it.
You can preview d59b181 at https://pr37922-d59b181.ngbuilds.io/. |
fs.list().forEach(path => { | ||
const file = fs.lookup(path)!; | ||
this.resources.set(path, new MockResponse(file.contents, {headers: file.headers})); | ||
withRootDirectory(newRootDir: string): MockServerStateBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So clean, I love it.
In some cases, it is useful to use a relative base href in the app (e.g. when an app has to be accessible on different URLs, such as on an intranet and the internet - see #25055 for a related discussion). Previously, the Angular ServiceWorker was not able to handle relative base hrefs (for example when building the with `--base-href=./`). This commit fixes this by normalizing all URLs from the ServiceWorker configuration wrt the ServiceWorker's scope. Fixes #25055 PR Close #37922
Some ServiceWorker operations and methods require normalized URLs. Previously, the generic `string` type was used. This commit introduces a new `NormalizedUrl` type, a special kind of `string`, to make this requirement explicit and use the type system to enforce it. PR Close #37922
…scope (#37922) The Angular ServiceWorker can serve requests to a special virtual path, `ngsw/state`, showing [information about its internal state][1], which can be useful for debugging. Previously, this would only work if the ServiceWorker's [scope][2] was the root directory (`/`). Otherwise, (e.g. when building the app with `--baseHref=/some/path/`), the ServiceWorker would fail to detect a request to `/some/path/ngsw/state` as matching `ngsw/state` and would not serve it with the debugging information. This commit fixes it by ensuring that the ServiceWorker's scope is taken into account when detecting a request to `ngsw/state`. [1]: https://angular.io/guide/service-worker-devops#locating-and-analyzing-debugging-information [2]: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/scope Fixes #30505 PR Close #37922
In some cases, it is useful to use a relative base href in the app (e.g. when an app has to be accessible on different URLs, such as on an intranet and the internet - see #25055 for a related discussion). Previously, the Angular ServiceWorker was not able to handle relative base hrefs (for example when building the with `--base-href=./`). This commit fixes this by normalizing all URLs from the ServiceWorker configuration wrt the ServiceWorker's scope. Fixes #25055 PR Close #37922
Some ServiceWorker operations and methods require normalized URLs. Previously, the generic `string` type was used. This commit introduces a new `NormalizedUrl` type, a special kind of `string`, to make this requirement explicit and use the type system to enforce it. PR Close #37922
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…scope (angular#37922) The Angular ServiceWorker can serve requests to a special virtual path, `ngsw/state`, showing [information about its internal state][1], which can be useful for debugging. Previously, this would only work if the ServiceWorker's [scope][2] was the root directory (`/`). Otherwise, (e.g. when building the app with `--baseHref=/some/path/`), the ServiceWorker would fail to detect a request to `/some/path/ngsw/state` as matching `ngsw/state` and would not serve it with the debugging information. This commit fixes it by ensuring that the ServiceWorker's scope is taken into account when detecting a request to `ngsw/state`. [1]: https://angular.io/guide/service-worker-devops#locating-and-analyzing-debugging-information [2]: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/scope Fixes angular#30505 PR Close angular#37922
…ngular#37922) This is in preparation of enabling the ServiceWorker to handle relative paths in `ngsw.json` (as discussed in angular#25055), which will require normalizing URLs in other parts of the ServiceWorker. PR Close angular#37922
…l ones (angular#37922) This commit makes the mock implementations used is ServiceWorker tests behave more similar to the actual ones. PR Close angular#37922
In some cases, it is useful to use a relative base href in the app (e.g. when an app has to be accessible on different URLs, such as on an intranet and the internet - see angular#25055 for a related discussion). Previously, the Angular ServiceWorker was not able to handle relative base hrefs (for example when building the with `--base-href=./`). This commit fixes this by normalizing all URLs from the ServiceWorker configuration wrt the ServiceWorker's scope. Fixes angular#25055 PR Close angular#37922
…ar#37922) Some ServiceWorker operations and methods require normalized URLs. Previously, the generic `string` type was used. This commit introduces a new `NormalizedUrl` type, a special kind of `string`, to make this requirement explicit and use the type system to enforce it. PR Close angular#37922
Various fixes to allow the Angular ServiceWorker to correctly work when the app has an absolute or relative base href.
See individual commits for details.
Fixes #25055 and #30505.