WEBrick嵌入式HTTP服务器程序库

联合创作 · 2023-10-01 13:46

WEBrick是Ruby中内嵌的HTTP服务器程序库

下面是一个调用 WEBrick 实现最简单的 HTTP 服务器的代码:

#!/usr/local/bin/ruby
require 'webrick'
include WEBrick

s = HTTPServer.new(
:Port => 2000,
:DocumentRoot => Dir::pwd + "/htdocs"
)

## mount subdirectories
s.mount("/ipr", HTTPServlet::FileHandler, "/proj/ipr/public_html")
s.mount("/~gotoyuzo",
HTTPServlet::FileHandler, "/home/gotoyuzo/public_html",
true) #<= allow to show directory index.

trap("INT"){ s.shutdown }
s.start
浏览 8
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报