ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
780 B

  1. require 'net/http'
  2. require 'uri'
  3. class WikiProxyController < ApplicationController
  4. def edit
  5. tag = params[:tag]
  6. uri = "http://localhost:4567/gollum/edit/#{ URI.encode_www_form_component(tag) }"
  7. begin
  8. res = fetch_with_redirect(uri)
  9. render html: res.body.html_safe, content_type: res.content_type
  10. rescue => e
  11. render plain: "Wiki システムとの通信に失敗しました:#{ e.message }", status: 502
  12. end
  13. end
  14. private
  15. def fetch_with_redirect uri_str, limit = 5
  16. raise 'Too many redirects' if limit == 0
  17. uri = URI.parse(uri_str)
  18. res = Net::HTTP.get_response(uri)
  19. if res.is_a? Net::HTTPRedirection
  20. location = res['location']
  21. fetch_with_redirect(location, limit - 1)
  22. else
  23. res
  24. end
  25. end
  26. end