This commit is contained in:
2025-06-07 18:54:10 +09:00
parent e8760ca1d8
commit b61027be4b
9 changed files with 226 additions and 3 deletions
@@ -0,0 +1,31 @@
require 'net/http'
require 'uri'
class WikiProxyController < ApplicationController
def edit
tag = params[:tag]
uri = "http://localhost:4567/gollum/edit/#{ URI.encode_www_form_component(tag) }"
begin
res = fetch_with_redirect(uri)
render html: res.body.html_safe, content_type: res.content_type
rescue => e
render plain: "Wiki システムとの通信に失敗しました:#{ e.message }", status: 502
end
end
private
def fetch_with_redirect uri_str, limit = 5
raise 'Too many redirects' if limit == 0
uri = URI.parse(uri_str)
res = Net::HTTP.get_response(uri)
if res.is_a? Net::HTTPRedirection
location = res['location']
fetch_with_redirect(location, limit - 1)
else
res
end
end
end