首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Ruby Rack -挂载一个默认读取index.html的简单web服务器

Ruby Rack -挂载一个默认读取index.html的简单web服务器
EN

Stack Overflow用户
提问于 2010-10-05 20:54:29
回答 4查看 10.5K关注 0票数 19

我正在尝试从本教程中获得一些信息:http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder

基本上,我希望有一个文件config.ru,告诉rack读取当前目录,这样我就可以像访问简单的apache服务器一样访问所有文件,还可以使用index.html file...is读取默认根目录。有什么方法可以做到吗?

我当前的config.ru如下所示:

代码语言:javascript
复制
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不能正常启动。

代码语言:javascript
复制
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

提前感谢

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3863781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档