我试图将我的shopify网址屏蔽为www.mywebsite.com/store
。我希望人们能够使用shopify网站,通常只需使用“www.mywebsite.com / store / * path /”
我正在使用rails应用程序,我已经掌握了基础知识,但它只适用于GET请求。我该如何处理POST请求?或者,有点不太理想,但有没有办法在遇到POST请求时逃脱屏蔽?
这是我的商店行动:
def store
path = params[:path].to_s
source_url = 'https://mystore.myshopify.com/' + path
source_content_type = ''
source_body = open(source_url) do |f|
source_content_type = f.content_type # "text/html"
f.read
end
if source_content_type == 'text/html'
output_base = request.base_url + '/store'
output_body = source_body.gsub(/\b(href|src|rel)="\/\//, '\1="https:\/\/')
output_body = output_body.gsub(/\b(href|src|rel)="\//, '\1="' + output_base + '/')
output_body = output_body.gsub(/\b(href|src|rel)="http:\/\/mystore\.myshopify\.com/, '\1="/store')
else
output_body = source_body
end
render :text => output_body, :content_type => source_content_type, :layout => false
end
这是我的路线:
get "/store" => "blog#store"
get "/store/*path" => "blog#store"