在最新版本中,您应该设置环境变量来配置证书
SSL_CRT_FILE=.cert/server.crtSSL_KEY_FILE=.cert/server.key
create-react-app不建议退出,因为您将无法无缝升级它。此外,您可以轻松获得有效的SSL证书而无需退出。
您将需要将证书复制到
node_modules/webpack-dev-server/ssl/server.pem。缺点是您需要手动复制文件。但是,实现这种无缝连接的一种方法是添加一个
postinstall创建符号链接的脚本。这是我创建的脚本:
#!/bin/bash# With create-react-app, a self signed (therefore invalid) certificate is generated.# 1. Create some folder in the root of your project# 2. Copy your valid development certificate to this folder# 3. Copy this file to the same folder# 4. In you package.json, under `scripts`, add `postinstall` script that runs this file.# Every time a user runs npm install this script will make sure to copy the certificate to the # correct locationTARGET_LOCATION="./node_modules/webpack-dev-server/ssl/server.pem"SOURCE_LOCATION=$(pwd)/$(dirname "./local-certificate/server.pem")/server.pemecho linking ${TARGET_LOCATION} TO ${SOURCE_LOCATION}rm -f ${TARGET_LOCATION} || trueln -s ${SOURCE_LOCATION} ${TARGET_LOCATION}chmod 400 ${TARGET_LOCATION} # after 30 days create-react-app tries to generate a new certificate and overwrites the existing one. echo "Created server.pem symlink"
您
package.json应该看起来像:
"scripts": { ... "postinstall": "sh ./scripts/link-certificate.sh"}
- 我的解决方案基于此线程
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)