Skip to content

Commit

Permalink
fix(react): full support custom secure host for module federation (#2…
Browse files Browse the repository at this point in the history
…1777)

Co-authored-by: Vadim Goy <vadim.goy@zoominfo.com>
  • Loading branch information
vadimka123 and Vadim Goy committed Feb 13, 2024
1 parent a0f761c commit 499659c
Showing 1 changed file with 14 additions and 7 deletions.
Expand Up @@ -98,7 +98,8 @@ async function startDevRemotes(
staticRemotes: string[];
devRemotes: string[];
},
context: ExecutorContext
context: ExecutorContext,
options: ModuleFederationDevServerOptions
) {
const devRemoteIters: AsyncIterable<{ success: boolean }>[] = [];

Expand All @@ -119,6 +120,10 @@ async function startDevRemotes(
},
{
watch: true,
...(options.host ? { host: options.host } : {}),
...(options.ssl ? { ssl: options.ssl } : {}),
...(options.sslCert ? { sslCert: options.sslCert } : {}),
...(options.sslKey ? { sslKey: options.sslKey } : {}),
...(isUsingModuleFederationDevServerExecutor
? { isInitialHost: false }
: {}),
Expand Down Expand Up @@ -291,7 +296,7 @@ export default async function* moduleFederationDevServer(
);
await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);

const devRemoteIters = await startDevRemotes(remotes, context);
const devRemoteIters = await startDevRemotes(remotes, context, options);

const staticRemotesIter =
remotes.staticRemotes.length > 0
Expand All @@ -313,6 +318,10 @@ export default async function* moduleFederationDevServer(
return;
}
try {
const host = options.host ?? 'localhost';
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${
options.port
}`;
const portsToWaitFor = staticRemotesIter
? [options.staticRemotesPort, ...remotes.remotePorts]
: [...remotes.remotePorts];
Expand All @@ -321,15 +330,13 @@ export default async function* moduleFederationDevServer(
waitForPortOpen(port, {
retries: 480,
retryDelay: 2500,
host: 'localhost',
host: host,
})
)
);

logger.info(
`NX All remotes started, server ready at http://localhost:${options.port}`
);
next({ success: true, baseUrl: `http://localhost:${options.port}` });
logger.info(`NX All remotes started, server ready at ${baseUrl}`);
next({ success: true, baseUrl: baseUrl });
} catch {
throw new Error(
`Timed out waiting for remote to start. Check above for any errors.`
Expand Down

0 comments on commit 499659c

Please sign in to comment.