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

feat(angular): add exposed methods for dynamic federation #9437

Merged
merged 1 commit into from Mar 22, 2022

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Mar 21, 2022

Current Behavior

We have no native solution currently for dynamic federation

Expected Behavior

Add a solution for native dynamic federation

Usage

In the bootstrap.ts file we set our remote definitions or use a function:

import { setRemoteDefinitions, setRemoteUrlResolver } from '@nrwl/angular/mfe';

// Straightforward method would be something as simple as:
fetch('/assets/manifest.json')
  .then((res) => res.json())
  .then(definitions => setRemoteDefinitons(definitions))

// where mainfest.json has shape
//
//   {
//      "login": "",
//      "todo": ""
//   }

// However, if more flexibility is needed
setRemoteUrlResolver(async (remoteName: string) => {
 const url = await fetch('/api/' + remoteName + '/config').then(res => res.json())
 return url;
});

We then load our remotes in our routing config via:

            {
              path: 'todo',
              loadChildren: () =>
                loadRemoteModule('todo', './Module').then(
                  (m) => m.RemoteEntryModule
                ),
              canActivate: [AuthGuard],
            },
            {
              path: 'login',
              loadChildren: () =>
                loadRemoteModule('login', './Module').then(
                  (m) => m.RemoteEntryModule
                ),
            }

Note: './Module' can be different if the user exposes more than one module from their remote.

@Coly010 Coly010 self-assigned this Mar 21, 2022
@nx-cloud
Copy link

nx-cloud bot commented Mar 21, 2022

☁️ Nx Cloud Report

CI ran the following commands for commit b6692a7. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 8 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Mar 21, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/Fd232TAWa1pJdfkXY8U5XN9eyynu
✅ Preview: Canceled

[Deployment for b6692a7 canceled]

@Coly010 Coly010 force-pushed the angular/dynamic-federation branch 2 times, most recently from ad388b9 to e27194c Compare March 21, 2022 17:29
@jaysoo
Copy link
Member

jaysoo commented Mar 21, 2022

LGTM. I guess there is a follow-up to add generators options for this?

@Coly010
Copy link
Contributor Author

Coly010 commented Mar 22, 2022

LGTM. I guess there is a follow-up to add generators options for this?

There will be yes 🙂

Copy link
Member

@leosvelperez leosvelperez left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@Coly010 Coly010 merged commit 0331b38 into nrwl:master Mar 22, 2022
@Coly010 Coly010 deleted the angular/dynamic-federation branch March 22, 2022 12:25
@github-actions
Copy link

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 Mar 19, 2023
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.

None yet

3 participants