environment-variablesdokkucreate-react-app

How to set an env variable with double quotes in dokku of a create-react-app based app?


I'm having trouble getting a create-react-app based application to correctly load environment variables containing double quotes:

First the dokku config shows this:

dokku config admin
=====> admin config vars
REACT_APP_API:           "https://example.com"
dokku@DokkuVM:~$ 

and my fetch calls look like this:

fetch(`${process.env.REACT_APP_API}/api/v1/whatever`)

which webpack compiles to (and of course does not work):

fetch(("\"https://example.com\"") + '/api/v1/whatever')

A similar setup is working locally, in my .env file I have:

REACT_APP_API="http://example.com"

Or another example, with JSON, which doesn't work:

dokku config:set BLOB="{"title": "The title of my application"}"
dokku config:set BLOB='{"title": "The title of my application"}'

Solution

  • You shouldn't use double quotes when setting values like that. Instead, do this:

    dokku config:set APP_NAME REACT_APP_API=http://example.com