benpickles / parklife

Render a Rack app (Rails/Sinatra/etc) to a static build so it can be served by Netlify, Now, GitHub Pages, S3, or any other web server.
https://parklife.dev
MIT License
193 stars 7 forks source link

404 response from path index.html - Using Rails #93

Closed damuz91 closed 1 year ago

damuz91 commented 1 year ago

Good day! Today I am playing around with Parklife. I just picked up a sample rails app i got published on github: https://github.com/damuz91/mi-bodega-rails Then i have added parklife to the Gemfile and tried to follow the step by step from the Readme. My Parklife file looks like this:

require_relative 'config/environment'
require 'parklife/rails'

Parklife.application.configure do |config|
end

Parklife.application.routes do
  root crawl: true
  get products_path
end

And i have included in my development.rb file:

Rails.application.config.hosts = nil

But when running parklife build I get the following error:

..Traceback (most recent call last):
        12: from /Users/damuz91/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:22:in `<main>'
        11: from /Users/damuz91/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:22:in `eval'
        10: from /Users/damuz91/.rvm/gems/ruby-2.7.0/bin/parklife:23:in `<main>'
         9: from /Users/damuz91/.rvm/gems/ruby-2.7.0/bin/parklife:23:in `load'
         8: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/parklife-0.5.1/exe/parklife:5:in `<top (required)>'
         7: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
         6: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
         5: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
         4: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
         3: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/parklife-0.5.1/lib/parklife/cli.rb:15:in `build'
         2: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/parklife-0.5.1/lib/parklife/application.rb:25:in `build'
         1: from /Users/damuz91/.rvm/gems/ruby-2.7.0/gems/parklife-0.5.1/lib/parklife/crawler.rb:27:in `start'
/Users/damuz91/.rvm/gems/ruby-2.7.0/gems/parklife-0.5.1/lib/parklife/crawler.rb:61:in `process_route': 404 response from path "index.html" (Parklife::HTTPError)

My routes.rb file:

Rails.application.routes.draw do
  root "home#dashboard"
  resources :products do
    member do
      get :new_movement
      post :create_movement
    end
  end
end

My app contains no authentication at all. When accessing / it renders my home#index page.

Can you please tell my why is it showing this error or what I am not understanding from the build process? Thanks and nice gem!

benpickles commented 1 year ago

First of all thanks for providing a completely reproducible issue 🙏🏻

The 404 response from path "index.html" issue is weird because isn't that just the root URL? Well apparently not because if you start the Rails server and visit /index.html you get a 404. The offending link being crawled comes from:

https://github.com/damuz91/mi-bodega-rails/blob/e3b97c8c447870290db697aa74959a06c0b6bbda/app/views/layouts/application.html.erb#L15

I get it, there isn't an /index route so Rails doesn't recognise an HTML version of a route that it doesn't know about. But it's still a surprise.

So if you fix that link you can build a static version of the site right? Not yet! Next I encountered a separate issue that's fixed in https://github.com/benpickles/parklife/pull/94.

But now if you update your Gemfile reference to gem 'parklife', github: 'benpickles/parklife' you should be able to build with Parklife.

FYI you don't need to add the get products_path route in your Parkfile because it gets crawled via the root - though explicitly specifying it doesn't do any harm.

damuz91 commented 1 year ago

Awesome, it did work! Thanks for replying back. Now i see that these static files are meant to be opened in a web server since they convert all routes to absolute paths instead of relative, so opening in the web browser locally won't allow it to be navigatable. Still pretty impressive.

I noticed that even tho the build script has the assets precompile command it is not executing it, so I have manually executed the assets:precompile and moved the assets folder to the build folder, then the static page started showing assets. I see your note that Parklife does not know anything about the assets.

Thanks again!