Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render a remote file with rails

I have the sitemap of www.mysite.com hosted on https://s3.amazonaws.com/mysite/sitemaps/sitemap1.xml.gz

Is it possible to configure Rails (routes, controllers, ...) to render the file sitemap1.xml under www.mysite.com/sitemap1.xml.gz?

Thanks.

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

like image 401
Topo Avatar asked Jul 30 '11 12:07

Topo


1 Answers

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

I'm trying 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 sitemap (index) file contains links to other sitemap files (sitemap1, sitemap2...) located at your site and not amazon.

like image 60
AndreiMotinga Avatar answered Oct 02 '22 16:10

AndreiMotinga