Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 want either the https://localhost:3000 to work, or else https://localhost:3001.

like image 250
Ringo Avatar asked Jun 15 '17 18:06

Ringo


People also ask

How do I change the port in Create React app?

To change the default port for a create-react-app project, update the start command in your package. json file to specify the port, e.g. "PORT=3456 react-scripts start" on macOS and Linux and "set PORT=3456 && react-scripts start" on Windows.


2 Answers

Set HTTPS=true before you run the start command.

Documentation

The implementation uses the HTTPS Environment Variable to determine which protocol to use when starting the server.

like image 155
Steve Buzonas Avatar answered Oct 30 '22 05:10

Steve Buzonas


You can edit your package.json scripts section to read:

"scripts": { "start": "set HTTPS=true&&react-scripts start", ... }

or just run set HTTPS=true&&npm start

Just a sidenote, for me, making this change breaks hot reloading for some reason....

-- Note: OS === Windows 10 64-Bit

like image 43
Smitty Avatar answered Oct 30 '22 07:10

Smitty