You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just documenting what I figured out to embed replayweb.page in a Ruby on Rails app (a Blacklight discovery implementation). Still working on our implementation of embedding WARCs, but in case anyone else runs into the same issues I did just getting it running I hope this is helpful.
I had a heck of a time getting Rails to register the service worker at ./replay/sw.js. First I tried registering the service worker as an object in the Rails app, but it turned out to be a red herring since the ui.js script really does all the heavy lifting. All I needed was to get the right path to sw.js which turned out to be tricky! I ended up using a gem called rails-static-router that allowed me to reroute the request for the sw.js file to the actual path on disk (in the Rails Public folder). So (using Rails 5):
/my-app/Gemfile
gem 'rails-static-router'
/my-app/config/routes.rb
get '/root-path/replay/sw.js', to: static('/replay/sw.js') # the `replay` folder is inside the app `Public` folder
That's it!
The text was updated successfully, but these errors were encountered:
Hi @mcampos-quinn, thanks for sharing this, and great to see this use case! Is there anything that you think would make this easier to work with Rails?
The idea was that users could just create a directory called replay that could contain the sw.js. Is that harder to do?
Would ./static/replay/sw.js be easier? If so, the path can be changed with the replayBase attribute, eg.
Honestly I'm not sure, I'm no Rails expert 🙃. I tried declaring different paths and using routing to redirect was the simplest solution I found. It would be great to not add another dependency to our code though! I'll do some more tinkering.
Wow, turns out I had tried and rejected using the replayBase attribute too quickly! I tried it again and it works as expected, with the replay/sw.js path under public in my app. Truly magical stuff.
Just documenting what I figured out to embed replayweb.page in a Ruby on Rails app (a Blacklight discovery implementation). Still working on our implementation of embedding WARCs, but in case anyone else runs into the same issues I did just getting it running I hope this is helpful.
I had a heck of a time getting Rails to register the service worker at
./replay/sw.js
. First I tried registering the service worker as an object in the Rails app, but it turned out to be a red herring since theui.js
script really does all the heavy lifting. All I needed was to get the right path tosw.js
which turned out to be tricky! I ended up using a gem calledrails-static-router
that allowed me to reroute the request for thesw.js
file to the actual path on disk (in the RailsPublic
folder). So (using Rails 5):/my-app/Gemfile
/my-app/config/routes.rb
That's it!
The text was updated successfully, but these errors were encountered: