serve current directory from command line

2019-01-16 00:13发布

could someone give me a hint, howto serve the current directory from command line with ruby? it would be great, if i can have some system wide configuration (e.g. mime-types) and simply launch it from every directory.

8条回答
叛逆
2楼-- · 2019-01-16 00:56

You can use the sinatra gem, though it doesn't do any directory listing for you, it serves files:

require 'sinatra' # gem
set :public_folder, '.'

then run that as a file, if in 1.8 add require 'rubygems' to the top first.

After running it then url's like

http://localhost:4567/file_name

should resolve to "./file_name" file.

http://localhost:4567 won't work however, since it doesn't "do" directory listings. See https://stackoverflow.com/a/12115019/32453 for a workaround there.

查看更多
Explosion°爆炸
3楼-- · 2019-01-16 01:01

I've never seen anything as compact as

python -m SimpleHTTPServer

for Ruby, Chris' answer shows up several times on Google.

查看更多
登录 后发表回答