Skip to content

Commit

Permalink
Remove confusing underscore from comments.json filename
Browse files Browse the repository at this point in the history
  • Loading branch information
mecampbellsoup committed Mar 5, 2015
1 parent 13a46a2 commit fb15f9c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type comment struct {
Text string `json:"text"`
}

const dataFile = "./_comments.json"
const dataFile = "./comments.json"

var commentMutex = new(sync.Mutex)

Expand Down
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.get('/comments.json', function(req, res) {
fs.readFile('_comments.json', function(err, data) {
fs.readFile('comments.json', function(err, data) {
res.setHeader('Content-Type', 'application/json');
res.send(data);
});
});

app.post('/comments.json', function(req, res) {
fs.readFile('_comments.json', function(err, data) {
fs.readFile('comments.json', function(err, data) {
var comments = JSON.parse(data);
comments.push(req.body);
fs.writeFile('_comments.json', JSON.stringify(comments, null, 4), function(err) {
fs.writeFile('comments.json', JSON.stringify(comments, null, 4), function(err) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-cache');
res.send(JSON.stringify(comments));
Expand Down
4 changes: 2 additions & 2 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

function routeRequest()
{
$comments = file_get_contents('_comments.json');
$comments = file_get_contents('comments.json');
switch($_SERVER["REQUEST_URI"]) {
case '/':
echo file_get_contents('./public/index.html');
Expand All @@ -23,7 +23,7 @@ function routeRequest()
'text' => $_POST['text']];

$comments = json_encode($commentsDecoded, JSON_PRETTY_PRINT);
file_put_contents('_comments.json', $comments);
file_put_contents('comments.json', $comments);
}
header('Content-Type: application/json');
header('Cache-Control: no-cache');
Expand Down
4 changes: 2 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
@app.route('/comments.json', methods=['GET', 'POST'])
def comments_handler():

with open('_comments.json', 'r') as file:
with open('comments.json', 'r') as file:
comments = json.loads(file.read())

if request.method == 'POST':
comments.append(request.form.to_dict())

with open('_comments.json', 'w') as file:
with open('comments.json', 'w') as file:
file.write(json.dumps(comments, indent=4, separators=(',', ': ')))

return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})
Expand Down
4 changes: 2 additions & 2 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
server = WEBrick::HTTPServer.new :Port => 3000, :DocumentRoot => root

server.mount_proc '/comments.json' do |req, res|
comments = JSON.parse(File.read('./_comments.json'))
comments = JSON.parse(File.read('./comments.json'))

if req.request_method == 'POST'
# Assume it's well formed
comments << req.query
File.write('./_comments.json', JSON.pretty_generate(comments, :indent => ' '))
File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' '))
end

# always return json
Expand Down

0 comments on commit fb15f9c

Please sign in to comment.