如何通过create

如何通过create,第1张

如何通过create

在最新版本中,您应该设置环境变量来配置证书

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"}
  • 我的解决方案基于此线程


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4899933.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存