How to create a https server on localhost

前端 未结 6 493
误落风尘
误落风尘 2021-01-30 08:47

I followed the tutorial below to create a https server https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/

and the program runs without errors

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 09:37

    I finally set up my create-react-app https dev server

    the reason why I'm doing this is to test device motion API on a mobile device.

    install mkcert https://github.com/FiloSottile/mkcert

    brew install mkcert
    
    mkcert -install
    

    generate cert files.

    mkcert -key-file ./.cert/key.pem -cert-file ./.cert/cert.pem ""
    

    use LAN IP address instead of "localhost", because we will open our https page on a mobile device that has connected to the same WiFi.

    create a .env file to set env variables

    HTTPS=true
    SSL_CRT_FILE=./.cert/cert.pem
    SSL_KEY_FILE=./.cert/key.pem
    

    start the dev server

    npm start
    

    last but not least, install the cert file on the mobile device, the .pem file generated by mkcert is located in ~/Library/Application Support/mkcert in my case.

    install cert file on an Android device

    https://support.google.com/pixelphone/answer/2844832?hl=en

    install cert file on an iOS device

    serve the .pem file on a static server, and open the file address on Safari

提交回复
热议问题