0
WEBrick 서버 인스턴스를 실행하고 브라우저에서 localhost : 2000/so_question을 가리키면 서버에서 다음과 같은 오류가 발생합니다 : i. ERROR /some_image.jpg를 찾을 수 없습니다. ii. ERROR /jquery.min.js을 찾을 수 없습니다.자산 파일을로드하는 중 WEBrick 오류가 발생했습니다
샘플 코드 :
require 'webrick'; include WEBrick
s = HTTPServer.new Port: 2000
class SoQuestion < HTTPServlet::AbstractServlet
def do_GET req, resp
resp.status = 200
resp['Content-Type'] = 'text/html'
resp.body = prep_body
end
def prep_body
body = %(
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
)
body << '<p>Hello, world!</p>'
body << "<img src='some_image.jpg'>"
body << "<script src='jquery.min.js'></script>"
body << '</body></html>'
end
end
s.mount '/so_question', SoQuestion
trap('INT'){s.shutdown}
s.start
어떻게 이러한 오류를 수정? Plz, pure-Ruby 솔루션을 제안하십시오 (보석, plz 없음).
감사합니다.
감사를 정적 파일을 제공합니다, 내 문제를 해결했다. – ThunderThunder