create-react-app: how to use https instead of http?

后端 未结 19 1121
眼角桃花
眼角桃花 2020-12-24 10:04

I was wondering if anyone knows how to use https on dev for the \'create-react-app\' environment. I can\'t see anything about that in the README or quick googling. I just wa

相关标签:
19条回答
  • 2020-12-24 11:11

    Windows (cmd.exe)

    set HTTPS=true&&npm start
    

    (Note: the lack of whitespace is intentional.)

    Windows (Powershell)

    ($env:HTTPS = "true") -and (npm start)
    

    Linux, macOS (Bash)

    HTTPS=true npm start
    

    Note that the server will use a self-signed certificate, so your web browser will almost definitely display a warning upon accessing the page.

    Custom SSL certificate

    HTTPS=true SSL_CRT_FILE=<SSLCert.crt> SSL_KEY_FILE=<SSLCert.key> npm start
    

    Linux, macOS (Bash)

    HTTPS=true SSL_CRT_FILE=<SSLCert.crt> SSL_KEY_FILE=<SSLCert.key> npm start
    

    To avoid doing it each time: You can include in the npm start script like so:

    {
      "start": "HTTPS=true react-scripts start"
    }
    

    Or you can create a .env file with HTTPS=true

    0 讨论(0)
提交回复
热议问题