Repository navigation
feat: load remotes from a URL with an offline cache - #12
Merged
Merged
Conversation
serveFederatedApps accepts an http(s) URL as an app location. Requests for mf://local/<app-id>/ are fetched from it in the main process, network first, with an on-disk copy served when the network fails, times out or answers an error status. Ported from @module-federation/tauri. The smoke test now also loads the remotes over HTTP, then again from the cache after the server stops. Refs #11
commit: |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #11 (step 1: offline cache; last-known-good rollback follows separately)
What
serveFederatedAppsaccepts anhttp(s)URL as an app location:mf://local/<app-id>/<path>is fetched from<url>/<path>in the main process. The renderer still sees one origin, so this needs no runtime plugin and no CORS setup, andmf-manifest.jsonremotes are covered (they aren't in@module-federation/tauri).Offline cache (ported from
@module-federation/tauri)GETresponses are cached on disk with their headers.x-mf-cache: stale. Error responses are never cached.content-encoding/content-length(the fetch already decoded the body) andset-cookie. Conditional andOriginrequest headers aren't forwarded.cache: { dir, connectTimeout, readTimeout }, orcache: falseto proxy without caching. The default directory is<sessionData>/module-federation.The proxy and cache live in
src/remote.ts, which doesn't importelectron(the fetch function is injected), so they are unit tested in Node.Tests
test/remote.test.ts: 18 tests against a local HTTP server, covering offline fallback, restart, refresh, broken deploys, connect and stalled-body timeouts, truncated bodies, the 30 s window, gzip, header forwarding, non-GETrequests and path traversal.pnpm smokenow loads each host three times: fromdist, with the remotes fetched from a local HTTP server, and after that server stops. The last pass also checks that the manifests are served from the cache.