我試圖從本教程獲得一些信息的簡單Web服務器:http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder紅寶石機架 - 安裝讀取index.html作爲默認
基本上我想有一個文件config.ru
告訴機架讀取當前目錄,所以我可以像訪問簡單的apache服務器一樣訪問所有文件,並使用index.html文件讀取默認的根目錄......有什麼辦法可以做到嗎?
我目前config.ru
看起來是這樣的:
run Rack::Directory.new('')
#this would read the directory but it doesn't set the root to index.html
map '/' do
file = File.read('index.html')
run Proc.new {|env| [200, {'Content-Type' => 'text/html'}, file] }
end
#using this reads the index.html mapped as the root but ignores the other files in the directory
所以我不知道如何從這裏出發......
我也試過這下面的教程的例子,但沒有按thin
」 t正常啓動。
builder = Rack::Builder.new do
run Rack::Directory.new('')
map '/' do
file = File.read('index.html')
run Proc.new {|env| [200, {'Content-Type' => 'text/html'}, file] }
end
end
Rack::Handler::Thin.run builder, :port => 3000
在此先感謝
FWIW,':port => 3000'應該是':Port => 3000' - 注意Port中的大寫字母「P」。 – briangonzalez 2013-10-12 16:43:51