Rails API with Create-React-App on Heroku
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
I don't know much about Heroku but presumably your server doesn't have Node.js?
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.
@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.
Update: @vldsoar If this PR gets merged then this could be closed @gaearon ?
That tutorial walks you through step by step.
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
@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 ?