2013-05-21 151 views
0

我试图实现http://blog.sosedoff.com/2011/04/09/serving-maintenance-page-with-rack-middleware/只有一个区别 - 我的消息是读像这样的整体* .html文件:输出到Web浏览器

def default_prompt(t) 
     File.open("public/tmp/maintenance/maintenance.html", "r").read 
    end 

和输出

if File.exists?(@file) 
    body = @block.nil? ? default_prompt(time_info) : @block.call(time_info) 
    res = Response.new 
    res.write(body) 
    res.finish 
    else 
    @app.call(env) 

但是我最终得到了html文件的文本,因为输出被<pre>标签包围。
我该如何解决这个问题?

回答

2

看起来您只有<pre>标签。实际发生的情况是,您要返回的结果不是对Rack正确形成的响应(您需要某种类型的内容标题来指示您要发回的内容)。你需要实现更多这样的东西:

if File.exists(@file) 
    maintenance_html = File.open(@file, "r").read 
    [200, {"Content-Type" => "text/html"}, maintenance_html] # This is a proper Rack response. 
else 
    @app.call(env) 

里面的中间件调用函数。