diff --git a/comments.json b/comments.json index 7bef77ad..28816136 100644 --- a/comments.json +++ b/comments.json @@ -8,5 +8,20 @@ "id": 1420070400000, "author": "Paul O’Shannessy", "text": "React is *great*!" + }, + { + "id": 1464988635157, + "author": "ben", + "text": "*abc*" + }, + { + "id": 1464988636500, + "author": "ben", + "text": "*abc*" + }, + { + "id": 1464988717637, + "author": "evil", + "text": "alert(1)" } -] +] \ No newline at end of file diff --git a/package.json b/package.json index e7491981..bf3360a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "name": "react-tutorial", "version": "0.0.0", + "private": true, + "license": "see LICENSE file", "description": "Code from the React tutorial.", "main": "server.js", "dependencies": { diff --git a/public/css/base.css b/public/css/base.css index 08de8f1b..c8cc35f7 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -35,9 +35,6 @@ h1, h2, h3, h4 { h1 { border-bottom: 1px solid #ddd; font-size: 2.5em; - font-weight: bold; - margin: 0 0 15px; - padding: 0; } h2 { diff --git a/public/index.html b/public/index.html index 34ebddf4..eb201204 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,11 @@ React Tutorial - - - - - + + + + +
diff --git a/public/scripts/example.js b/public/scripts/example.js index c249427a..6493fea9 100644 --- a/public/scripts/example.js +++ b/public/scripts/example.js @@ -12,7 +12,8 @@ var Comment = React.createClass({ rawMarkup: function() { - var rawMarkup = marked(this.props.children.toString(), {sanitize: true}); + var md = new Remarkable(); + var rawMarkup = md.render(this.props.children.toString()); return { __html: rawMarkup }; }, diff --git a/server.php b/server.php index 75fae215..e510136b 100644 --- a/server.php +++ b/server.php @@ -27,11 +27,11 @@ function routeRequest() { - $comments = file_get_contents('comments.json'); $uri = $_SERVER['REQUEST_URI']; if ($uri == '/') { echo file_get_contents('./public/index.html'); } elseif (preg_match('/\/api\/comments(\?.*)?/', $uri)) { + $comments = file_get_contents('comments.json'); if($_SERVER['REQUEST_METHOD'] === 'POST') { $commentsDecoded = json_decode($comments, true); $commentsDecoded[] = [ diff --git a/server.py b/server.py index 5cf598df..03c6213d 100644 --- a/server.py +++ b/server.py @@ -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)), debug=True)