@bimo-dk/nexus-runtime
v0.3.0
Published
Angular providers + services + components for Bimo-Nexus hosts and remotes
Readme
@bimo-dk/nexus-runtime
Angular providers for Bimo-Nexus remotes and hosts. Bundles runtime config, self-registration, HTTP interceptors and dynamic federation into one-call providers — so your bootstrap.ts stays focused on business logic.
Installation
npm install @bimo-dk/nexus-runtime @bimo-dk/nexus-buildPeer dependencies (must be installed in your app):
@angular/core,@angular/common,@angular/router(^19)@angular-architects/native-federation(^19) — only required for hostsrxjs(^7.8)
Remote (5-line bootstrap)
// src/bootstrap.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { provideNexusRemote } from '@bimo-dk/nexus-runtime';
import EntryComponent from './app/remote-entry/entry.component';
bootstrapApplication(EntryComponent, {
providers: [
provideNexusRemote({
entry: EntryComponent,
configDefaults: {
registryUrl: 'http://localhost:3000',
nexusToken: 'dev-token',
},
}),
],
});// src/app/remote-entry/entry.component.ts
import { Component } from '@angular/core';
import { NexusRemote } from '@bimo-dk/nexus-build';
@NexusRemote() // name & route auto-inferred
@Component({ template: '<h1>OK</h1>' })
export default class EntryComponent {}At bootstrap:
/assets/config.jsonis fetched and merged on top ofconfigDefaults- The remote POSTs itself to
${registryUrl}/remotes(or PUTs if already registered) - Name/route/exposedModule are read from the
@NexusRemotedecorator metadata - URL is derived from
window.location(orpublicUrlif set in runtime config)
Host (1 provider, full dynamic federation)
// src/bootstrap.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { provideNexusHost } from '@bimo-dk/nexus-runtime';
import { AppShell } from './app/app-shell.component';
bootstrapApplication(AppShell, {
providers: [
provideRouter([]), // start with empty routes; nexus fills them in
provideNexusHost({
configDefaults: {
registryUrl: '/api',
nexusToken: 'dev-token',
staticBackupUrl: '/assets/registry-backup/remotes.json',
},
}),
],
});At bootstrap the host:
- Fetches enabled remotes from registry (with cache → static backup fallback chain)
- Opens a WebSocket to
/wsfor live updates - Calls
loadRemoteModule()for each remote, registers a route - Reacts to WebSocket broadcasts to add/remove routes without reload
Read state from DynamicNexusService in your shell:
import { Component, inject } from '@angular/core';
import { DynamicNexusService } from '@bimo-dk/nexus-runtime';
@Component({ ... })
export class AppShell {
readonly nexus = inject(DynamicNexusService);
// nexus.loadedRemotes() — signal<RemoteConfig[]>
// nexus.failedRemotes() — signal<Map<string, string>>
// nexus.registryOnline() — computed signal
}Runtime config (/assets/config.json)
Both providers fetch /assets/config.json at bootstrap. Typical template (substituted by nginx entrypoint at container start):
{
"registryUrl": "${REGISTRY_URL}",
"nexusToken": "${NEXUS_TOKEN}"
}NexusRuntimeConfig fields:
| Field | Description |
|---|---|
| registryUrl | Base URL of the registry API |
| nexusToken | Token for X-Nexus-Token header |
| configAssetPath | Override /assets/config.json path |
| publicUrl | Override the URL a remote announces to the registry |
| staticBackupUrl | Host-only: path to the backup remotes JSON |
What's bundled
Both providers register the same baseline:
NEXUS_CONFIGinjection token populated from runtime configHttpClientwithnexusAuthInterceptor+correlationIdInterceptor
Then they add their role-specific pieces:
- Remote →
SelfRegisterServiceruns once at bootstrap - Host →
RegistryService+RegistryWebSocketService+DynamicNexusServiceare started and route registration begins
Manual wiring (escape hatch)
If you need more control, all the building blocks are exported:
import {
NEXUS_CONFIG,
provideNexusConfig,
SelfRegisterService,
DynamicNexusService,
RegistryService,
RegistryWebSocketService,
nexusAuthInterceptor,
correlationIdInterceptor,
} from '@bimo-dk/nexus-runtime';