Skip to content

feat(module-federation): use proxy servers to proxy to single file server for static remotes#26782

Merged
jaysoo merged 3 commits into
masterfrom
mf/use-express-proxies
Jul 18, 2024
Merged

feat(module-federation): use proxy servers to proxy to single file server for static remotes#26782
jaysoo merged 3 commits into
masterfrom
mf/use-express-proxies

Conversation

@Coly010

@Coly010 Coly010 commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

Current Behavior

Remotes that are served for a host are usually served from a single file server running on a single port.
We perform some mapping logic during the build of the host application to update the locations the remotes can be found at to point to the single file server.

This works, but it's also wrong, as it breaks the flow that users expect.
It also breaks dynamic remotes.

Expected Behavior

Continue to serve the remotes from a single file server, as this helps reduce the amount of resources used on developers machines.
Use express to create proxy servers that will proxy requests from the original remote location to the single file server.

This allows applications to continue to work without us having to interfere and map any remote locations.
It also solves the issue with dynamic remotes.

Related Issue(s)

Fixes #26318

@Coly010 Coly010 self-assigned this Jul 1, 2024
@vercel

vercel Bot commented Jul 1, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Jul 18, 2024 5:04pm

@Coly010 Coly010 force-pushed the mf/use-express-proxies branch from c576e10 to ba829f4 Compare July 2, 2024 11:00
@Coly010 Coly010 force-pushed the mf/use-express-proxies branch from 7b2d218 to d7bba68 Compare July 2, 2024 14:40
@Coly010 Coly010 force-pushed the mf/use-express-proxies branch from d7bba68 to f22d782 Compare July 2, 2024 15:24
@Coly010 Coly010 force-pushed the mf/use-express-proxies branch from 700a473 to 69666a8 Compare July 3, 2024 14:57
@ndcunningham ndcunningham force-pushed the mf/use-express-proxies branch from 69666a8 to d616f59 Compare July 5, 2024 19:10
@ndcunningham ndcunningham force-pushed the mf/use-express-proxies branch from d616f59 to 914edbc Compare July 8, 2024 16:37
@ndcunningham ndcunningham force-pushed the mf/use-express-proxies branch from 914edbc to c48d7e2 Compare July 9, 2024 13:50
@jaysoo jaysoo force-pushed the mf/use-express-proxies branch from c48d7e2 to e49f239 Compare July 17, 2024 17:22
@jaysoo jaysoo force-pushed the mf/use-express-proxies branch from e49f239 to a9be846 Compare July 17, 2024 17:43
@jaysoo jaysoo marked this pull request as ready for review July 17, 2024 17:44
@jaysoo jaysoo requested review from a team and jaysoo as code owners July 17, 2024 17:44
@jaysoo jaysoo requested a review from Cammisuli July 17, 2024 17:44
@jaysoo jaysoo force-pushed the mf/use-express-proxies branch from a9be846 to 1f1a2b3 Compare July 17, 2024 17:49

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removed this because it needs to be defaulted from the results of getRemotes (just like in React). Otherwise there could be a port conflict if one of the dev remotes has a port that's host port + 1.

@jaysoo jaysoo enabled auto-merge (squash) July 18, 2024 02:52
@jaysoo jaysoo disabled auto-merge July 18, 2024 02:52
@Coly010 Coly010 force-pushed the mf/use-express-proxies branch 2 times, most recently from 7b78039 to e4bf406 Compare July 18, 2024 15:11
@Coly010 Coly010 force-pushed the mf/use-express-proxies branch from e4bf406 to e3dcd49 Compare July 18, 2024 17:02
@jaysoo jaysoo merged commit a549b9b into master Jul 18, 2024
@jaysoo jaysoo deleted the mf/use-express-proxies branch July 18, 2024 17:46
@VanTigranyan

Copy link
Copy Markdown

Hi @Coly010, thanks a lot for this fix. Is there a documentation that I can look into understand how this works?

FrozenPandaz pushed a commit that referenced this pull request Jul 22, 2024
…rver for static remotes (#26782)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Remotes that are served for a host are usually served from a single file
server running on a single port.
We perform some mapping logic during the build of the host application
to update the locations the remotes can be found at to point to the
single file server.

This works, but it's also wrong, as it breaks the flow that users
expect.
It also breaks dynamic remotes.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Continue to serve the remotes from a single file server, as this helps
reduce the amount of resources used on developers machines.
Use express to create proxy servers that will proxy requests from the
original remote location to the single file server.

This allows applications to continue to work without us having to
interfere and map any remote locations.
It also solves the issue with dynamic remotes.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26318

(cherry picked from commit a549b9b)
@Coly010

Coly010 commented Jul 24, 2024

Copy link
Copy Markdown
Contributor Author

@VanTigranyan No documentation as of yet, but it is coming.

Essentially, the process is now

  1. Build all static remotes
  2. Start a single http-server serving all built remotes at an arbitrary port
  3. For each static remote, start an express server at the port defined in the remote's serve target
    3a. express server will proxy requests to the http-server with the correct endpoint for the remote.

This means we continue to get the machine resource savings without doing any under the hood mapping of remote locations etc.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular MFE setup is broken after migration from 17 to 18 or 19

3 participants