我试图在本地开发中使用https 'create-react-app'。我使用这个网站作为创建证书的教程,并让windows信任它:https://zeropointdevelopment.com/how-to-get-https-working-in-windows-10-localhost-dev-environment/
这是我的。env文件。
SSL_CRT_FILE=client-1.local.crt
SSL_KEY_FILE=client-1.local.key
HTTPS=true
这是我的package。json
...
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
...
之后,我使用
npm开始
命令,转到https://localhost:3000/
- 在Firefox中,我收到
安全连接失败;细节很少的错误;一个错误在连接到localhost:3000时发生。PR_CONNECT_RESET_ERROR
- 在Chrome上我收到
连接被重置
我也检查了这篇文章create-react-app:如何使用https而不是http?但我没看到任何对我有帮助的东西。我用的是windows 10。
有什么想法吗?谢谢你
按照官方的create-react-app网站的解决方案,你应该运行:
set HTTPS=true&&npm start
这将运行"npm start"对于你和浏览器应该允许你查看页面
我在使用Edge时也遇到了类似的问题。我是这样解决的
- 在边缘浏览器类型URL:- edge://net-internals/#hsts
- on"删除域安全策略";进入"localhost"并按"删除"键。
- 重开localhost: 3000/
*chrome也有类似的链接chrome://net-internals/#hsts