Run built frontend (react) as a static file in Rails

Viewed 120

So I'm trying to run a React app as a static html file (it's index file) in a Rails app. This works in express/node and it's quite common in projects, but i can't find a solution for this in Rails. So the react app is already built and i'm trying to serve it as a static html from the /public folder. EDIT However i can't get it to run, it shows me that it's loaded, there's no error in the rails console or the browser console, however nothing gets shown on the screen.

routes.rb

get "react_app" => "projects#react_app" 

projects_controller.rb

def react_app
  render :file => 'public/react_app/public/index.html'
end

i also have

config.serve_static_assets = true

I'm using Rails 5.2. I am not using yarn, i'm trying to run it via the plain assets pipeline.

Any ideas ? Or is there another better way to do it maybe ?

  • This app needs to be all in one place, and unfortunately gems such as react-on-rails or react-rails are not an option, since they require too much strange customization and often crash due to Redux.
0 Answers
Related