Skip to content

Commit 5345d4b

Browse files
committed
ruby server
1 parent 9e0ecad commit 5345d4b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

server.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'webrick'
2+
require 'json'
3+
4+
comments = react_version = JSON.parse(File.read('./_comments.json'))
5+
6+
puts 'Server started: http://localhost:3000/'
7+
8+
root = File.expand_path './public'
9+
server = WEBrick::HTTPServer.new :Port => 3000, :DocumentRoot => root
10+
11+
server.mount_proc '/comments.json' do |req, res|
12+
if req.request_method == 'POST'
13+
# Assume it's well formed
14+
comments << req.query
15+
end
16+
17+
# always return json
18+
res['Content-Type'] = 'application/json'
19+
res.body = comments.to_json
20+
end
21+
22+
trap 'INT' do server.shutdown end
23+
24+
server.start

0 commit comments

Comments
 (0)