Skip to content

Commit ddeb573

Browse files
committed
format ruby
1 parent f185fe8 commit ddeb573

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

server.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root
2020

2121
server.mount_proc '/comments.json' do |req, res|
22-
comments = JSON.parse(File.read('./comments.json'))
23-
24-
if req.request_method == 'POST'
25-
# Assume it's well formed
26-
comment = {}
27-
req.query.each do |key, value|
28-
comment[key] = value.force_encoding('UTF-8')
22+
comments = JSON.parse(File.read('./comments.json'))
23+
24+
if req.request_method == 'POST'
25+
# Assume it's well formed
26+
comment = {}
27+
req.query.each do |key, value|
28+
comment[key] = value.force_encoding('UTF-8')
29+
end
30+
comments << comment
31+
File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' '))
2932
end
30-
comments << comment
31-
File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' '))
32-
end
33-
34-
# always return json
35-
res['Content-Type'] = 'application/json'
36-
res['Cache-Control'] = 'no-cache'
37-
res.body = JSON.generate(comments)
33+
34+
# always return json
35+
res['Content-Type'] = 'application/json'
36+
res['Cache-Control'] = 'no-cache'
37+
res.body = JSON.generate(comments)
3838
end
3939

4040
trap 'INT' do server.shutdown end

0 commit comments

Comments
 (0)