Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create React App: Set HTTPS flag in package.json based on .env variable

To enable create react app to run in SSL mode, we need to set HTTPS=true in the package.json like this

    "start": "HTTPS=true react-scripts start",

However, I would like this only in production and not when development happens locally. I have a .env file, and would like to use a flag REACT_APP_USE_SSL=true in production and then REACT_APP_USE_SSL=false locally.

My question is, how can I use this environment variable in package.json? Or is there another way to seamlessly switch between HTTP and HTTPS mode for development and production environment?

like image 581
Swamy g Avatar asked Feb 28 '26 14:02

Swamy g


1 Answers

As mentioned in the comment by @kiranvj, (and also after the reading the doc myself), this is easier than the other complicated solutions I was trying to implement.

You can just set HTTPS=true or HTTPS=false in your .env file and create react app will pick it up.

like image 136
Swamy g Avatar answered Mar 03 '26 04:03

Swamy g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!