How to visualize a remote file with rails

I have a sitemap www.mysite.com located at https://s3.amazonaws.com/mysite/sitemaps/sitemap1.xml.gz

Can I configure Rails (routes, controllers, ...) to render the sitemap1.xml file at www.mysite.com/sitemap1.xml.gz?

Thanks.

Ps. the reason the sitemap is under AWS is: https://github.com/kjvarga/sitemap_generator/wiki/Generate-Sitemaps-on-read-only-filesystems-like-Heroku

+6
source share
3 answers

based on https://github.com/kjvarga/sitemap_generator/issues/173

I am trying to do this ... in routes.rb

get 'sitemap(:id).:format.:compression' => 'sitemap#show'

in sitemap_controller.rb

 class SitemapController < ApplicationController def show data = open("http://{ENV['AWS_BUCKET_PROD']}.s3.amazonaws.com/sitemaps/sitemap#{params[:id]}.xml.gz") send_data data.read, :type => data.content_type end end 

Also make sure that the sitemap (index) file contains links to other Sitemap files (sitemap1, sitemap2 ...) located on your site, not amazon.

+2
source

As I understand it, you are deploying a read-only file system such as Heroku.

If so, here are some articles to help:

0
source

Create a controller that will be redirected to the location of the Amazon S3 file and create an appropriate route for it.

routes.rb:

 match 'sitemap1.xml.gz' => 'site_map#redirect' 

site_map_controller.b:

 class SiteMapController < ApplicationController def redirect redirect_to 'https://s3.amazonaws.com/mysite/sitemaps/sitemap1.xml.gz' end end 
-1
source

Source: https://habr.com/ru/post/893938/


All Articles