We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 00c2d8f commit 6647f84Copy full SHA for 6647f84
server.rb
@@ -19,7 +19,7 @@
19
server = WEBrick::HTTPServer.new Port: port, DocumentRoot: root
20
21
server.mount_proc '/api/comments' do |req, res|
22
- comments = JSON.parse(File.read('./comments.json'))
+ comments = JSON.parse(File.read('./comments.json', encoding: 'UTF-8'))
23
24
if req.request_method == 'POST'
25
# Assume it's well formed
@@ -28,7 +28,11 @@
28
comment[key] = value.force_encoding('UTF-8')
29
end
30
comments << comment
31
- File.write('./comments.json', JSON.pretty_generate(comments, indent: ' '))
+ File.write(
32
+ './comments.json',
33
+ JSON.pretty_generate(comments, indent: ' '),
34
+ encoding: 'UTF-8'
35
+ )
36
37
38
# always return json
0 commit comments