How do I add https to yarn run?

24.4k views Asked by At

I am trying to run a yarn server with

$ yarn run start --https

which starts a server, but with http not https. The --https option works for another project that I was working on, but not this one. I was wondering if I need to set something in package.json as well to enable https. For reference, this is the github project that I cloned and am using: https://github.com/googlecreativelab/teachable-machine-boilerplate.

4

There are 4 answers

2
Explosion Pills On BEST ANSWER

The boilerplate uses a development server budo, so yarn start essentially runs budo dist. You can still pass options to it.

budo has no https option, but it does have an --ssl option for this purpose.

yarn start --ssl
0
Leonardo On

I will answer because any of these answers don't work for me! Its all copied of the internet, but doesn't works fine!

To run in HTTPS your react app follow the guide below:

First you don't need to put HTTPS=true in "start" tag, instead, you need in your VS Code terminal, for example, put set HTTPS=true

so, yarn start and it will run on https

This is the output running with https this is the output running with https

Setting on "start" script tag occurs an error like "HTTPS' is not recognized as an internal or external command, so, I followed this way.

After that I installed my certificate generated with mkcert tool

0
scottlittle On

While @Explosion Pills answer did create an SSL connection for localhost, there was a problem using my local IP. It turned out that I should have been using budo directly instead of yarn. I remedied this with:

npm install budo -g

And then running this to create the https server:

budo main.js --ssl

Hopefully my admission of naiveness can discretely help someone in the future!

0
roj4s On

Explained on docs:

    HTTPS=true npm start

or set it on scripts section of your package.json:

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