我有 Angular v19 应用程序,并且我正在使用 SSG 和以下 angular.json 设置
{
...
"prerender":{
"routesFile": "prerender-urls.txt",
"discoverRoutes": false
},
"ssr": false
...
}
当我渲染一些路由时,它可以工作,但是当我尝试渲染大量路由(例如 10K)时,后端 api 返回响应速度较慢。
因为角度构建管道会抛出这样的错误超时错误
Request for: http://ng-localhost/artists was aborted.
TimeoutError: The operation was aborted due to timeout
at t.signal.addEventListener.once (.angular/prerender-root/0e49d623-08ac-4921-af23-47b186294be5/chunk-4RSAFBPM.mjs:106:5215)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
at EventTarget.dispatchEvent (node:internal/event_target:760:26)
at abortSignal (node:internal/abort_controller:370:10)
at AbortController.abort (node:internal/abort_controller:392:5)
at EventTarget.abort (node:internal/deps/undici/undici:5038:21)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
at EventTarget.dispatchEvent (node:internal/event_target:760:26)
at abortSignal (node:internal/abort_controller:370:10)
at Timeout._onTimeout (node:internal/abort_controller:127:7)
X [ERROR] An error occurred while prerendering route '/artists'.
Error: Terminating worker thread
at Object.ThreadTermination (...piscina\dist\errors.js:5:30)
at WorkerInfo.destroy (...piscina\dist\worker_pool\index.js:107:43)
at ThreadPool._removeWorker (...piscina\dist\index.js:250:20)
at ThreadPool.destroy (...piscina\dist\index.js:434:18)
at WorkerPool.destroy (...piscina\dist\index.js:631:65)
at ...@angular\build\src\utils\server-rendering\prerender.js:147:35
at async Promise.all (index 151)
at async renderPages (...@angular\build\src\utils\server-rendering\prerender.js:151:9)
at async prerenderPages (...@angular\build\src\utils\server-rendering\prerender.js:93:49)
at async executePostBundleSteps (...@angular\build\src\builders\application\execute-post-bundle.js:68:73)
我研究并尝试了许多解决方法,但没有找到适当的解决方案来增加这个超时问题。
有没有办法劫持 Angular 的构建管道或其他方式来增加这个超时时间。
我相信这是一个非常常见的情况,但我在网上找不到任何资源
更新:我在 Angular 仓库上打开了一个 git 问题
当我更新到 v19 时,我现在注意到 API 调用以地址“ng-localhost”开头。 当使用 http://localhost 或
http://127.0.0.1 启动 API 调用时,问题得到解决。