Skip to content

Rails API with Create-React-App on Heroku #1358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vldsoar opened this issue Jan 6, 2017 · 6 comments
Closed

Rails API with Create-React-App on Heroku #1358

vldsoar opened this issue Jan 6, 2017 · 6 comments

Comments

@vldsoar
Copy link

vldsoar commented Jan 6, 2017

Original post: http://stackoverflow.com/questions/39774143/rails-api-with-create-react-app-on-heroku-npm-command-not-found

I created Rails API backend app and inside the app in a folder client I created create-react-app for my frontend. It works well on my local machine but does not work on heroku with an error:

npm: command not found

This is the structure of the app:

rails-app

  • app
    • controller
    • model
    • ...
  • client
    • package.json
    • index.jsx
    • ...
  • config
  • db
  • ...
  • Procfile

Inside Procfile I have:

web: cd client && npm start
api: bundle exec rails s -p 3001

@gaearon
Copy link
Contributor

gaearon commented Jan 6, 2017

I don't know much about Heroku but presumably your server doesn't have Node.js?

@vldsoar
Copy link
Author

vldsoar commented Jan 6, 2017

Yes! A example: https://www.fullstackreact.com/articles/how-to-get-create-react-app-to-work-with-your-rails-api/

The structure is pretty much the same.

@notrab
Copy link

notrab commented Jan 9, 2017

@vldsoar The Rails core team are looking to merge Webpacker when it's ready, most likely in Rails 5.1

I'd recommend deploying your frontend and API separately. The API version of Rails does a great job in removing any "view layer" dependencies.

@notrab
Copy link

notrab commented Jan 10, 2017

Update: @vldsoar If this PR gets merged then this could be closed @gaearon ?

That tutorial walks you through step by step.

@shabanraza
Copy link

I have created a project using create react app and the backend rails api is on different server and i am facing cross origin unable hit any post api from

@notrab
Copy link

notrab commented Jan 11, 2017

@shabanraza While this isn't a Create React App issue, you might want to checkout the rack cors gem.

Maybe this can be closed @gaearon ?

@gaearon gaearon closed this as completed Feb 11, 2017
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants