Class | Rascut::Httpd |
In: |
lib/rascut/httpd.rb
|
Parent: | Object |
INDEX | = | <<-EOF <html> <head> <title>Rascut</title> <style> * { margin:0; padding:0; } #content { text-align:center; } </style> <script type="text/javascript" src="/js/swfobject.js"></script> <!--__RELOAD__--> </head> <body> <div id="content"></div> <script type="text/javascript"> var so = __SWFOBJECT__; window.onload = function() { __SWF_VARS__ so.addVariable('rascut', 'true'); so.write("content"); } </script> </body> </html> EOF |
RELOAD_SCRIPT | = | <<-EOF <script type="text/javascript"> var Rascut = new Object; Rascut.xhr = (function() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } else { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); } } })(); Rascut.reloadObserver = function() { var x = Rascut.xhr; x.open('GET', '/reload?' + (new Date()).getTime(), true); x.onreadystatechange = function() { try { if (x.readyState == 4) { if (x.status == 200 && Number(x.responseText) == 1) { // thanks os0x! so.attributes.swf = so.attributes.swf + '+'; so.write('content'); Rascut.reloadObserver(); } else { setTimeout(Rascut.reloadObserver, 5000); } } } catch(e) { setTimeout(Rascut.reloadObserver, 5000); } } x.send(null); } Rascut.swf = function() { return document.getElementById('idswf'); } Rascut.reloadObserver(); </script> EOF |
command | [R] |
# File lib/rascut/httpd.rb, line 42 42: def initialize(command) 43: @command = command 44: @threads = [] 45: end
# File lib/rascut/httpd.rb, line 94 94: def reload! 95: while t = @threads.pop 96: t.run 97: end 98: end
# File lib/rascut/httpd.rb, line 48 48: def start 49: swf_path = command.root.to_s 50: logger.debug "swf_path: #{swf_path}" 51: vendor = Pathname.new(__FILE__).parent.parent.parent.join('vendor') 52: logger.debug "vendor_path: #{vendor}" 53: reload = reload_handler 54: index = index_handler 55: 56: #app = Rack::FixedBuilder.new do 57: # use Rack::ShowExceptions 58: # map('/reload') { run reload } 59: # map('/swf/') { run Rack::File.new(swf_path) } 60: # map('/') { run index } 61: #end 62: 63: urls = [] 64: urls.concat(config_url_mapping) if config[:mapping] 65: 66: urls.concat([ 67: ['/js/swfobject.js', Rack::ShowExceptions.new(Httpd::FileOnly.new(vendor.join('js/swfobject.js').to_s))], 68: ['/swf', Rack::ShowExceptions.new(Rack::File.new(swf_path))], 69: ['/reload', Rack::ShowExceptions.new(reload_handler)], 70: ['/proxy', Rack::ShowExceptions.new(proxy_handler)], 71: ['/', Rack::ShowExceptions.new(index_handler)] 72: ]) 73: logger.debug 'url mappings: ' + urls.map{|u| u.first}.inspect 74: app = Rack::URLMap.new(urls) 75: port = config[:port] || 3001 76: host = config[:bind_address] || '0.0.0.0' 77: 78: _args = [app, {:Host => host, :Port => port}] 79: server_handler = detect_server 80: Thread.new(_args) do |args| 81: server_handler.run *args 82: end 83: logger.info "Start #{server_handler} http://#{host}:#{port}/" 84: end