Ruby Ruby Simple HTTP Server With Rack

camel · December 13, 2012 · Last by lgn21st replied at December 13, 2012 · 4048 hits

把当前目录作为 web server 的根目录,用于解决 Chrome 本地 AJAX 请求Origin null is not allowed by Access-Control-Allow-Origin. 问题。类似 Python 的 SimpleHTTPServer。

2 步搞定:

1. 安装 rack,并新建 rack 配置文件 config.ru(只需运行一次)

gem install rack
echo "run Rack::Directory.new('')" > ~/config.ru

2. 切换到任意目录运行

rackup ~/config.ru

如果觉得命令长就建立 alias alias rp='rackup ~/config.ru'

访问即可:http://locahost:9292/

更多http://rubyer.me/blog/2012/12/12/ruby-simple-http-server-with-rack/

1 Floor has deleted

看了你的博客后,发现其实用 Py 最简单啊

python -m SimpleHTTPServer

#2 楼 @lgn21st python 是比较简单。但 rackup 再加上 alias 已经够用了,比以前把静态 html 复制到 rails 的 public 下方便多了,呵呵。

#3 楼 @camel 希望有朝一日,类 SimpleHTTPServer 的这么一个 feature 能进rack,这样就不依赖默认的 config.ru 了。

You need to Sign in before reply, if you don't have an account, please Sign up first.