angular - .NET Core 2.2 + Angular 7“xhr_streaming”永无止境
问题描述
我正在设置一个 .NET Core Web API 后端,前端有一个 Angular 7 SPA。我正在使用 Microsoft 的 SpaServices 和 StaticFiles 包将两者链接到一个项目中。
当我运行 Web 应用程序时,控制台选项卡显示 sockjs WebSocket 警告,而网络选项卡显示来自 sockjs 的名为“xhr_streaming”的东西,它永远保持打开状态。
这种行为正常吗?还是我没有正确设置/配置某些东西?
除了使用 Rider 生成 Web API 和使用 Angular CLI 生成 Angular 7 应用程序之外,我没有对项目做任何事情。我似乎无法在网上找到与此问题相关的很多内容,但我可能没有正确搜索。
这是我在 Web API 中的启动。我只关注我为将其与 Angular 链接所做的配置。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Rest of ConfigureServices are unrelated
services.AddSpaStaticFiles(configuration =>
{
// RootPath = "ClientApp/dist"
configuration.RootPath = serviceProvider.GetService<IOptions<SpaConfig>>().Value.RootPath;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Rest of Configure is irrelevant
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
"default",
"{controller}/{action}/{id?}");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer("start");
}
});
}
}
Angular 方面确实没有什么可以显示的,因为在使用ng new
.
基本上我只是想知道这种行为是否是预期的,或者我是否做错了什么。
以下是警告和网络阅读的一些截图:
和警告:
解决方案
当我调用从服务的构造函数返回承诺的函数时发生在我身上。函数调用包含一个 api 获取请求。一旦我删除了函数调用,xhr_streaming 就不再是一个永无止境的请求了。
推荐阅读
- linux - 如何使用另一个 Debian 软件包安装 Docker?
- ios - 无法在 iOS 模拟器中使用 Apple 登录
- android - 如何在 TopAppBar 下方显示 BodyScreen?
- xml - XSLT 从字符串输入中包含的数字中查找总和
- sql - 触发器已创建但执行事件会导致数字或值错误
- spring-boot - 如何在 Spring Boot 应用程序的消费者端启用 Rest API 请求和响应日志记录
- flutter - 嗨,我一直在尝试在 Flutter 中使用 CheckBoxListTile
- flutter - 常量变量必须用常量值初始化
- python - 在pygame中临时保存图像
- java - ThreadLocal 即使在清理后也会导致内存泄漏?