我想通过Ruby在我的局域网上生成本地服务器(如localhost/8000)(我不喜欢创建word)我研究了互联网,但我无法做到。 我的目标是在本地服务器上显示html页面,由Ruby使用。 我该怎么做?如何在Ruby中生成本地服务器
require 'socket'
我使用斯坦达特图书馆插座但是当我刷新页面提示错误。
require 'socket'
server = TCPServer.new('localhost', 2345)
loop do
socket = server.accept
request = socket.gets
STDERR.puts request
response = "Hello World!\n"
socket.print "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: #{response.bytesize}\r\n" +
"Connection: close\r\n"
socket.print "\r\n"
socket.print response
socket.close
end
'rails s'启动本地服务器 – brito
请问您可以提供更多信息吗? –
在终端中,导航到Rails项目根文件夹,输入'rails s'并按回车。 – brito