mars / heroku-cra-node

⚛️ How to use create-react-app with a custom Node server on Heroku
MIT License
927 stars 226 forks source link

Using with runtime envs? #34

Closed mb8z closed 5 years ago

mb8z commented 5 years ago

Hello there, I've been using your buildpack for create-react-app for quite a few projects now – all of them using separate heroku apps as APIs.

Today I wanted to do use it again for an app that has a setup just like the one in this repo. It works perfectly fine, but what I'm missing the most are runtime envs.

My question is – is it possible to use somehow use this feature?

I've added an additional buildpack to app.json (the one that's being used in the create-react-app-buildpack) but it does not seem to work :(

{
  "name": "react-app-with-api",
  "description": "Server for handling both API and React requests",
  "scripts": {},
  "env": {},
  "formation": {
    "web": {
      "quantity": 1
    }
  },
  "addons": [],
  "buildpacks": [
    {
      "url": "heroku/nodejs"
    },
    {
      "url": "https://github.com/mars/create-react-app-inner-buildpack"
    }
  ]
}

PS Thanks for the awesome work!

mars commented 5 years ago

Hi @Ancinek ,

I think your approach to add the inner buildpack should work (good idea!), but nodejs buildpack should to be the last one, since it actually starts the runtime process via npm start. So, set create-react-app-inner-buildpack as the first buildpack.

Also, you you'll need to set the bundle location, since it's in a different place than create-react-buildpack puts it:

heroku config:set JS_RUNTIME_TARGET_BUNDLE=/app/react-ui/build/static/js/*.js
mb8z commented 5 years ago

@mars I've just deployed the changed that you propose and it works just as you expected! :tada:

Thanks for the hint! I'm sure it will be helpful to more people in here!

mars commented 5 years ago

Awesome 🙌 I'll add this info to README!