create-react-app如何在本地配置https

create-react-app如何在本地配置https

1、在项目根目录建立文件夹 ssl,在文件夹下建立两个文件 cert.pem key.pem。

cert.pem

-----BEGIN CERTIFICATE-----
MIIEUjCCArqgAwIBAgIQcnkWtB8T/B/e5sU0jsVlXTANBgkqhkiG9w0BAQsFADBt
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExITAfBgNVBAsMGGFsc2NA
QzAyRjQzN1ZNTDdIIChBTFNDKTEoMCYGA1UEAwwfbWtjZXJ0IGFsc2NAQzAyRjQz
N1ZNTDdIIChBTFNDKTAeFw0yMTExMTcwMjQ0NTVaFw0yNDAyMTcwMjQ0NTVaMEwx
JzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBjZXJ0aWZpY2F0ZTEhMB8GA1UE
CwwYYWxzY0BDMDJGNDM3Vk1MN0ggKEFMU0MpMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAslpMJn93y8WFIG6D1hNEe72Bilc2CB5JxqCaRgZjajhuo+mv
VZXLG0qoJFq2bpx+O/OCKJjwMSR6a+CMVdI1OLHhgIRKUmKbm2SzRhP7m8FDsfXs
yuSpG9VeIUrVDqz1OTGT0GBnHPF3o+1DaetNh2X4KnvNIyphzCaHiiOYwRazSnIp
fJIckXAjZP4bA/GBQ/4yKZzI93cRe44P1ScvYSc0qAVa67udJfYX27OU11uLQymS
UECtqMEpC+ktHe5wM4U/rXvbJUMI4uOclPQPQ0WgWEZUwCKAMVF3xwf99lEUEYPn
uOV5FCGYeFhcrLO5foXROFAk0j1WVsdmQwMaOwIDAQABo4GOMIGLMA4GA1UdDwEB
/wQEAwIFoDATBgNVHSUEDDAKBggrBgEFBQcDATAfBgNVHSMEGDAWgBQqno88pqFE
GKX2JYfyT3NpazMRATBDBgNVHREEPDA6gggqLmVsZS5tZYILKi5lbGVuZXQubWWC
CWxvY2FsaG9zdIcEfwAAAYcQAAAAAAAAAAAAAAAAAAAAATANBgkq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6axPlYfmP6+TAxRBw15a2FAz1T8i1d9iNeblXoK8Cr7s5nt5K3mrdJxh7Dd
ckdAWh4YzPkzo2MVL7DMQQ==
-----END PRIVATE KEY-----

在webpack.dev.js的devServer节点 加

    https: {
      key: fs.readFileSync(path.resolve(__dirname, "./../ssl/key.pem")),
      cert: fs.readFileSync(path.resolve(__dirname, "./../ssl/cert.pem")),
    },

引入库

const fs = require("fs")
const path = require("path")

 

posted on 2022-02-23 16:38  漫思  阅读(806)  评论(1编辑  收藏  举报

导航