* Creates or retrieves a `ServerRouter` instance based on the provided manifest and URL. * * If the manifest contains pre-built routes, a new `ServerRouter` is immediately created. * Otherwise, it builds the router by extracting routes from the Angular configuration * asynchronously. Thi
(manifest: AngularAppManifest, url: URL)
| 46 | * @returns A promise resolving to a `ServerRouter` instance. |
| 47 | */ |
| 48 | static from(manifest: AngularAppManifest, url: URL): Promise<ServerRouter> { |
| 49 | if (manifest.routes) { |
| 50 | const routeTree = RouteTree.fromObject(manifest.routes); |
| 51 | |
| 52 | return Promise.resolve(new ServerRouter(routeTree)); |
| 53 | } |
| 54 | |
| 55 | // Create and store a new promise for the build process. |
| 56 | // This prevents concurrent builds by re-using the same promise. |
| 57 | ServerRouter.#extractionPromise ??= extractRoutesAndCreateRouteTree({ url, manifest }) |
| 58 | .then(({ routeTree, errors }) => { |
| 59 | if (errors.length > 0) { |
| 60 | throw new Error( |
| 61 | 'Error(s) occurred while extracting routes:\n' + |
| 62 | errors.map((error) => `- ${error}`).join('\n'), |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | return new ServerRouter(routeTree); |
| 67 | }) |
| 68 | .finally(() => { |
| 69 | ServerRouter.#extractionPromise = undefined; |
| 70 | }); |
| 71 | |
| 72 | return ServerRouter.#extractionPromise; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Matches a request URL against the route tree to retrieve route metadata. |
no test coverage detected