小编sgt*_*r85的帖子

如何设置本地环境以在 https 上运行

我正在尝试通过 https local 运行我的 React 应用程序。我已按照本教程的步骤进行操作,已正确安装mkcert,并且我的项目的根目录当前如下所示:

|-- my-react-app
    |-- package.json
    |-- localhost.pem
    |-- localhost-key.pem
    |--... 
Run Code Online (Sandbox Code Playgroud)

我的 package.json 文件如下所示:

"scripts": {
    "start": "HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem react-scripts start",
    ...
Run Code Online (Sandbox Code Playgroud)

然而,当我运行 npm start 时,我收到此错误:

'HTTPS' is not recognized as an internal or external command, operable program or batch file.

我还尝试在根目录中创建一个.env文件并添加如下变量:

HTTPS=true
SSL_CERT_FILE=localhost.pem
SSL_KEY_FILE=localhost-key.pem
Run Code Online (Sandbox Code Playgroud)

但是,当我以这种方式运行应用程序时,我收到一条警告,指出我的连接不安全。

我花了一些时间在谷歌上搜索错误,但到目前为止仍然无法找到解决方案。

https localhost ssl-certificate reactjs mkcert

3
推荐指数
1
解决办法
4830
查看次数

标签 统计

https ×1

localhost ×1

mkcert ×1

reactjs ×1

ssl-certificate ×1