And*_*ham 7 server-side-rendering angular asp.net-core-5.0
我正在创建一个新的 Angular 网站,并认为我会从新的 .NET 5 开始,但我在添加 SSR 时遇到了一些问题。
我创建了一个新网站并使用添加了一个 Angular 客户端,ng new client-app然后使用添加了 SSRng add @nguniversal/express-engine --client-project=client-app
我也可以使用电源外壳通过执行运行角应用npm run dev:ssr和一切正常,但是当我试图更新我的Startup.cs通过改变剧本来看,使用SSRUseAngularCliServer来自start于dev:ssr它建立和启动,但在浏览器中有错误:
:50740/browser-sync/socket.io/?EIO=3&transport=polling&t=NPHWxVs:1 Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR
zone-evergreen.js:2845 GET https://localhost:50740/browser-sync/socket.io/?EIO=3&transport=polling&t=NPHX5az net::ERR_SSL_PROTOCOL_ERROR
Run Code Online (Sandbox Code Playgroud)
我认为这些都是因为服务器使用的是http不https
如果我让启动指向start一切正常,但我没有得到 SSR 引擎,我很困惑现在如何启动它,因为该UseSpaPrerendering软件包已过时且不再包含在内。
如何启动 SSR 节点服务器并将其配置为使用 https?
这应该如何设置,以便我的开发环境尽可能接近我的生产环境?
更新
我一直在阅读文档,我相信我明白发生了什么,首先ERR_SSL_PROTOCOL_ERROR是因为socket.io硬编码使用 http 但看起来它重用了基本 url(包括 https,当在网站中使用 SSL)所以这只是简单地复制,但 AngularCliServer 仅适用于 http。如果您查看来源,则有评论
// Everything we proxy is hardcoded to target http://localhost because:
// - the requests are always from the local machine (we're not accepting remote
// requests that go directly to the Angular CLI middleware server)
// - given that, there's no reason to use https, and we couldn't even if we
// wanted to, because in general the Angular CLI server has no certificate
Run Code Online (Sandbox Code Playgroud)
最重要的是,如果您希望使用预渲染进行调试,您将被迫关闭项目的 SSL。
其次,主要问题是由于NodeServices.NET Core 团队已折旧且不再维护。看起来有很多关于放弃支持的抱怨,微软表示它需要是一个公开维护的项目,他们没有兴趣维护它。简而言之,不再有任何方法可以使用内置功能启动 Node 服务器。
Blazor 确实有一个执行 JavaScript 代码的库 JsInterop,也许这可能是使用<component />标签助手或类似的东西的可能答案?
| 归档时间: |
|
| 查看次数: |
849 次 |
| 最近记录: |