通过IIS Express与SSL运行时的Web-App热填充

发布于 2025-01-20 10:52:14 字数 1804 浏览 1 评论 0原文

由Micosoft Visual Studio创建的项目“ ASP.NET具有React+Redux”模板。在这种情况下,IIS Express运行的应用程序。但是,用于React-App的热弹加载不起作用,并且显示了控制台中的错误:“ WebSocket连接到'wss:// localhost:54691/ws'失败:“

经过一些研究,我找到了一个解决方案:在IIS设置中禁用SSL 。但是,当启用SSL时,如何使用热装加载来实现?

package.json依赖项:

"dependencies": {
    "@emotion/react": "^11.8.2",
    "@emotion/styled": "^11.8.1",
    "@mui/material": "^5.5.2",
    "@reduxjs/toolkit": "^1.8.1",
    "history": "4.10.1",
    "node-sass": "^6.0.1",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-scripts": "5.0.0",
    "react-redux": "~7.2.6",
    "react-router-dom": "6.2.1",
    "redux": "4.1.2",
    "redux-thunk": "2.4.1",
    "typescript": "4.4.4"
  },

启动集群

  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:48763",
      "sslPort": 44373
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyProject": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }

WebSocketClient.js:16 WebSocket connection to 'wss://localhost:54691/ws' failed: 
WebSocketClient @   WebSocketClient.js:16
initSocket  @   socket.js:24
./node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=54691&pathname=%2Fws&logging=none&reconnect=10   @   index.js:273
options.factory @   react refresh:6
__webpack_require__

Created project by Micosoft Visual Studio "ASP.NET with React+Redux" template. In that case app running by IIS Express. But hot-reload for react-app doesn't work and shows error in console: "WebSocket connection to 'wss://localhost:54691/ws' failed:"

After some research, I found a solution: disable SSL in IIS settings. But how can I achieve using hot reload when SSL is enabled?

package.json dependencies:

"dependencies": {
    "@emotion/react": "^11.8.2",
    "@emotion/styled": "^11.8.1",
    "@mui/material": "^5.5.2",
    "@reduxjs/toolkit": "^1.8.1",
    "history": "4.10.1",
    "node-sass": "^6.0.1",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-scripts": "5.0.0",
    "react-redux": "~7.2.6",
    "react-router-dom": "6.2.1",
    "redux": "4.1.2",
    "redux-thunk": "2.4.1",
    "typescript": "4.4.4"
  },

launchSettings.json generated by template (SSL enabled)

  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:48763",
      "sslPort": 44373
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyProject": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }

error message:

WebSocketClient.js:16 WebSocket connection to 'wss://localhost:54691/ws' failed: 
WebSocketClient @   WebSocketClient.js:16
initSocket  @   socket.js:24
./node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=54691&pathname=%2Fws&logging=none&reconnect=10   @   index.js:273
options.factory @   react refresh:6
__webpack_require__

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文