Skip to content

Commit

Permalink
Merge pull request reactjs#133 from akabraham/master
Browse files Browse the repository at this point in the history
Remove shadowing of file builtin in server.py. PEP8 formatting
  • Loading branch information
zpao committed May 10, 2016
2 parents 2be1a2d + 82424fa commit 81bbc6f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@
app = Flask(__name__, static_url_path='', static_folder='public')
app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))


@app.route('/api/comments', methods=['GET', 'POST'])
def comments_handler():

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

if request.method == 'POST':
newComment = request.form.to_dict()
newComment['id'] = int(time.time() * 1000)
comments.append(newComment)
new_comment = request.form.to_dict()
new_comment['id'] = int(time.time() * 1000)
comments.append(new_comment)

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

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',
'Access-Control-Allow-Origin': '*'
}
)

return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache', 'Access-Control-Allow-Origin': '*'})

if __name__ == '__main__':
app.run(port=int(os.environ.get("PORT",3000)))
app.run(port=int(os.environ.get("PORT", 3000)))

0 comments on commit 81bbc6f

Please sign in to comment.