Class: Mamemose::Server
Instance Method Summary collapse
- #file(filename) ⇒ Object
-
#initialize(port) ⇒ Server
constructor
A new instance of Server.
- #server ⇒ Object
- #start ⇒ Object
Methods included from HTML
#footer_html, #header_html, #link_list, #search_form
Methods included from Path
#docpath, #escape, #escaped_basename, #fullpath, #showpath, #uri
Constructor Details
#initialize(port) ⇒ Server
Returns a new instance of Server.
34 35 36 37 38 |
# File 'lib/mamemose.rb', line 34 def initialize(port) @mamemose = WEBrick::HTTPServer.new({ :Port => port ? port.to_i : PORT }) trap(:INT){finalize} trap(:TERM){finalize} end |
Instance Method Details
#file(filename) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mamemose.rb', line 64 def file(filename) @mamemose.mount_proc('/') do |req, res| res['Cache-Control'] = 'no-cache, no-store, must-revalidate' res['Pragma'] = 'no-cache' res['Expires'] = '0' res = req_file(File.absolute_path(filename), res, true) res.content_type = CONTENT_TYPE end start end |
#server ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mamemose.rb', line 44 def server @mamemose.mount_proc('/') do |req, res| res['Cache-Control'] = 'no-cache, no-store, must-revalidate' res['Pragma'] = 'no-cache' res['Expires'] = '0' p fullpath(req.path) if req.path =~ /^\/search/ res = req_search(req, res) elsif File.directory?(fullpath(req.path)) res = req_index(req, res) elsif File.exists?(fullpath(req.path)) res = req_file(fullpath(req.path), res, false) else res.status = WEBrick::HTTPStatus::RC_NOT_FOUND end end start end |
#start ⇒ Object
40 41 42 |
# File 'lib/mamemose.rb', line 40 def start @mamemose.start end |