TimeoutException:具有react的Asp.net Core 2.2,请求超时时间为50秒

时间:2019-02-24 09:43:25

标签: reactjs iis asp.net-core create-react-app

当我在IIS服务器上使用VS 2017运行项目时,发生超时异常

  

TimeoutException:在50秒的超时时间内,create-react-app服务器未开始侦听请求。

我的package.json文件

{
  "name": "Invest_Me",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.12",
    "@fortawesome/free-brands-svg-icons": "^5.7.0",
    "@fortawesome/free-regular-svg-icons": "^5.7.0",
    "@fortawesome/free-solid-svg-icons": "^5.6.3",
    "@fortawesome/react-fontawesome": "^0.1.4",
    "bootstrap": "^4.2.1",
    "jquery": "^3.3.1",
    "node-sass": "^4.11.0",
    "react": "^16.0.0",
    "react-dom": "^16.7.0",
    "react-redux": "^5.1.1",
    "react-router-bootstrap": "^0.24.4",
    "react-router-dom": "^4.2.2",
    "react-router-redux": "^5.0.0-alpha.8",
    "react-scripts": "^2.1.3",
    "reactstrap": "^7.1.0",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "rimraf": "^2.6.2"
  },
  "devDependencies": {
    "@babel/core": "^7.3.3",
    "@babel/plugin-transform-react-jsx": "^7.3.0",
    "@storybook/addon-actions": "^4.1.12",
    "@storybook/addon-links": "^4.1.12",
    "@storybook/addons": "^4.1.12",
    "@storybook/react": "^4.1.12",
    "ajv": "^6.0.0",
    "babel-eslint": "^9.0.0",
    "babel-loader": "^8.0.5",
    "cross-env": "^5.2.0",
    "eslint": "5.12.0",
    "eslint-config-react-app": "^2.1.0",
    "eslint-plugin-flowtype": "^2.50.3",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.11.1"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "scripts": {
    "start": "rimraf ./build && react-scripts start",
    "build": "react-scripts build",
    "test": "cross-env CI=true react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint": "eslint ./src/",
    "storybook": "start-storybook -p 9009 -s public",
    "build-storybook": "build-storybook -s public"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

我也尝试过解决 .UseKestrel(...)

Program.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>()
                    .UseKestrel(o => { o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); });

但是错误存在

Stacktrace

System.TimeoutException: The create-react-app server did not start listening for requests within the timeout period of 50 seconds. Check the log output for error information.
   at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout[T](Task`1 task, TimeSpan timeoutDelay, String message)
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
   at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

如何增加create-react-app服务器的超时时间

  

当我尝试通过cmd在ClientApp文件夹中运行npm start时,效果很好

2 个答案:

答案 0 :(得分:0)

用于设置create-react-app的StartupTimeout

添加这些Startup.cs Configure方法

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    if (env.IsDevelopment())
    {
        spa.Options.StartupTimeout = TimeSpan.FromSeconds(120);
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
 });

答案 1 :(得分:-1)

您可以使用system.TimeSpan。 但是问题尚未解决。仍然低于错误消息。 “ TimeoutException:create-react-app服务器未在0秒的超时时间内开始侦听请求。请检查日志输出以获取错误信息。”

解决方案:

您可以使用下面的链接,这将解决问题。 https://docs.microsoft.com/en-us/aspnet/core/client-side/spa/react?view=aspnetcore-3.1&tabs=visual-studio

  1. 在命令提示符下,切换到ClientApp子目录,然后启动CRA开发服务器: cd ClientApp npm start
  2. 修改ASP.NET Core应用程序以使用外部CRA服务器实例,而不是启动自己的实例。在您的Startup类中,将spa.UseReactDevelopmentServer调用替换为以下内容: spa.UseProxyToSpaDevelopmentServer(“ http:// localhost:3000”); 按F5