3

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?

Swamy g
  • 2,106
  • 4
  • 23
  • 35
  • 1
    We can do that, check this section in docs https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used – kiranvj Aug 05 '20 at 16:53
  • 1
    Thank you @kiranvj, I've added an answer. – Swamy g Aug 05 '20 at 16:59

1 Answers1

1

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.

Swamy g
  • 2,106
  • 4
  • 23
  • 35