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://www.benpickles.com/articles/90-introducing-parklife
MIT License
188 stars 7 forks source link

301 when force_ssl = true #99

Open Spone opened 1 year ago

Spone commented 1 year ago

I was trying out parklife in a Rails project where config/production.rb contains:

config.force_ssl = true

In this case, I got:

301 response from path "/" (Parklife::HTTPError)

When changing the config option to false, I was able to run static-build.

Do you think there's a way to prevent this? (or maybe just add a notice in the README)

benpickles commented 1 year ago

By default Parklife makes its mock requests to http://example.com but you can change this in your Parkfile:

Parklife.application.config.base = 'https://www.benpickles.com'

Or by passing a --base to bin/static-build at runtime - as in the generated GitHub Actions workflow:

https://github.com/benpickles/parklife/blob/24728101162ff7771a712f52d2e33d7dacc4f075/lib/parklife/templates/github_pages.yml#L27

Now your app will think it's serving an https request for your chosen domain and won't respond with a 301.

Configuring the correct base for your build allows you to use full URLs where necessary - in things like feed links and social media/Open Graph URLs.