From 0d7ca5b4553ab2649c8e8dbd97868fe86d49e4a9 Mon Sep 17 00:00:00 2001 From: Mantas Kaveckas Date: Wed, 6 Jan 2016 17:08:04 +0200 Subject: [PATCH 01/23] Remove unessessary px suffix from size of zero pixels --- public/css/base.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/css/base.css b/public/css/base.css index bf382be3..08de8f1b 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -23,7 +23,7 @@ code { font-family: "Bitstream Vera Sans Mono", Consolas, Courier, monospace; font-size: 12px; margin: 0 2px; - padding: 0px 5px; + padding: 0 5px; } h1, h2, h3, h4 { From 46a9a9a8bb2573f1960305825ff8e924aa17d338 Mon Sep 17 00:00:00 2001 From: Anthony Ross Date: Sat, 23 Jan 2016 20:05:05 -0500 Subject: [PATCH 02/23] nil is false in ruby nil is false in ruby so the ternary operator can be used with more idiomatic ruby. Also added a comment to show how to execute with a custom port. --- server.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.rb b/server.rb index eed401ae..d7f1121e 100644 --- a/server.rb +++ b/server.rb @@ -11,7 +11,9 @@ require 'webrick' require 'json' -port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i +# default port to 3000 or overwrite with PORT variable by running +# $ PORT=3001 ruby server.rb +port = ENV['PORT'] ? ENV['PORT'].to_i : 3000 puts "Server started: http://localhost:#{port}/" From e50157d498bb3a9d80ae334594753b55abe78554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Sat, 23 Jan 2016 22:21:02 -0800 Subject: [PATCH 03/23] Ensure Ruby server doesn't have duplicate id fields in json Alternative approach to #115 --- server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.rb b/server.rb index eed401ae..d902b4f6 100644 --- a/server.rb +++ b/server.rb @@ -25,7 +25,7 @@ # Assume it's well formed comment = { id: (Time.now.to_f * 1000).to_i } req.query.each do |key, value| - comment[key] = value.force_encoding('UTF-8') + comment[key] = value.force_encoding('UTF-8') unless key == 'id' end comments << comment File.write( From 3fba2d4e1ee9b5ab5253a0c1cdcdcc9bd7879f7b Mon Sep 17 00:00:00 2001 From: maxbittker Date: Sun, 24 Jan 2016 14:57:56 -0500 Subject: [PATCH 04/23] added permissive CORS header middleware function --- server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server.js b/server.js index ac87898a..c31d1e64 100644 --- a/server.js +++ b/server.js @@ -23,6 +23,11 @@ app.set('port', (process.env.PORT || 3000)); app.use('/', express.static(path.join(__dirname, 'public'))); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); +app.use(function(req, res, next) { + //set permissive CORS header + res.setHeader('Access-Control-Allow-Origin', '*'); + next(); +}); app.get('/api/comments', function(req, res) { fs.readFile(COMMENTS_FILE, function(err, data) { From d90d36b0c235d05d878837eca43f37a2421c32cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 25 Jan 2016 16:20:03 -0800 Subject: [PATCH 05/23] Clean up some code in the JS server, add comments --- server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index c31d1e64..b5a7218a 100644 --- a/server.js +++ b/server.js @@ -23,9 +23,15 @@ app.set('port', (process.env.PORT || 3000)); app.use('/', express.static(path.join(__dirname, 'public'))); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); + +// Additional middleware which will set headers that we need on each request. app.use(function(req, res, next) { - //set permissive CORS header + // Set permissive CORS header - this allows this server to be used only as + // an API server in conjunction with something like webpack-dev-server. res.setHeader('Access-Control-Allow-Origin', '*'); + + // Disable caching so we'll always get the latest comments. + res.setHeader('Cache-Control', 'no-cache'); next(); }); @@ -35,7 +41,6 @@ app.get('/api/comments', function(req, res) { console.error(err); process.exit(1); } - res.setHeader('Cache-Control', 'no-cache'); res.json(JSON.parse(data)); }); }); @@ -61,7 +66,6 @@ app.post('/api/comments', function(req, res) { console.error(err); process.exit(1); } - res.setHeader('Cache-Control', 'no-cache'); res.json(comments); }); }); From 304a251432b255635eeedccee23897c0d3684395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 25 Jan 2016 16:42:19 -0800 Subject: [PATCH 06/23] Add cache control headers to perl server --- server.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/server.pl b/server.pl index 517e1621..73c2713d 100644 --- a/server.pl +++ b/server.pl @@ -19,6 +19,7 @@ any [qw(GET POST)] => '/api/comments' => sub { my $self = shift; my $comments = decode_json (do { local(@ARGV,$/) = 'comments.json';<> }); + $self->res->headers->cache_control('no-cache'); if ($self->req->method eq 'POST') { From 7b675c89180cc50ce00fcf8f4bac39054102ec40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 25 Jan 2016 16:35:03 -0800 Subject: [PATCH 07/23] Add CORS headers to servers --- server.go | 2 ++ server.php | 1 + server.pl | 1 + server.py | 2 +- server.rb | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 2224328d..934a4cfc 100644 --- a/server.go +++ b/server.go @@ -84,11 +84,13 @@ func handleComments(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Access-Control-Allow-Origin", "*") io.Copy(w, bytes.NewReader(commentData)) case "GET": w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Access-Control-Allow-Origin", "*") // stream the contents of the file to the response io.Copy(w, bytes.NewReader(commentData)) diff --git a/server.php b/server.php index 6b8880c8..75fae215 100644 --- a/server.php +++ b/server.php @@ -45,6 +45,7 @@ function routeRequest() } header('Content-Type: application/json'); header('Cache-Control: no-cache'); + header('Access-Control-Allow-Origin: *'); echo $comments; } else { return false; diff --git a/server.pl b/server.pl index 73c2713d..c3212b9c 100644 --- a/server.pl +++ b/server.pl @@ -20,6 +20,7 @@ my $self = shift; my $comments = decode_json (do { local(@ARGV,$/) = 'comments.json';<> }); $self->res->headers->cache_control('no-cache'); + $self->res->headers->access_control_allow_origin('*'); if ($self->req->method eq 'POST') { diff --git a/server.py b/server.py index 451fbacd..5cf598df 100644 --- a/server.py +++ b/server.py @@ -30,7 +30,7 @@ def comments_handler(): 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'}) + 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))) diff --git a/server.rb b/server.rb index fc81b701..698f4339 100644 --- a/server.rb +++ b/server.rb @@ -40,6 +40,7 @@ # always return json res['Content-Type'] = 'application/json' res['Cache-Control'] = 'no-cache' + res['Access-Control-Allow-Origin'] = '*' res.body = JSON.generate(comments) end From 19aadd8a295acbfefbfd1f562073b0685bf60528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 16 Feb 2016 13:20:50 -0800 Subject: [PATCH 08/23] Update CDN links to latest versions --- public/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index c6494446..21340e72 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,11 @@ React Tutorial - - + + - - + +
From 31fe8d2ad766853ac5427c2fef08f2cfd37dcc33 Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Thu, 31 Mar 2016 20:23:09 +0200 Subject: [PATCH 09/23] Update CDN links to latest versions --- public/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 21340e72..4a560b84 100644 --- a/public/index.html +++ b/public/index.html @@ -5,10 +5,10 @@ React Tutorial - - - - + + + + From cd5dbc7a3c88aa60c04129310cac8f12af48c9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Thu, 7 Apr 2016 15:41:18 -0700 Subject: [PATCH 10/23] Use v15 --- public/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 4a560b84..8b84e266 100644 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,8 @@ React Tutorial - - + + From 2be1a2d6999b8f47c34e52e5a5b05bd6713343fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Fri, 8 Apr 2016 13:53:45 -0700 Subject: [PATCH 11/23] Use 15.0.1 --- public/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 8b84e266..34ebddf4 100644 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,8 @@ React Tutorial - - + + From 82424fa6ce90f384e418c54bd9bdc61216e550d8 Mon Sep 17 00:00:00 2001 From: Andrew Abraham Date: Tue, 10 May 2016 15:53:38 -0700 Subject: [PATCH 12/23] Remove shadowing of file builtin in server.py. PEP8 formatting --- server.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/server.py b/server.py index 5cf598df..fad15a66 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))) From 4fa16fde3795ff7047322f28320cffc3b2b385ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Fri, 20 May 2016 10:28:43 -0700 Subject: [PATCH 13/23] Add private & license fields to package.json --- package.json | 2 ++ 1 file changed, 2 insertions(+) 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": { From 06b89a1b5d1abe74f58163efeed80959c993ee52 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Fri, 3 Jun 2016 14:35:54 -0700 Subject: [PATCH 14/23] Use remarkable instead of marked (#140) Closes #139. --- public/index.html | 2 +- public/scripts/example.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 34ebddf4..a76aaada 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@ - +
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 }; }, From 64a6dfca72aca4d13ab4cbf23c50eba8b9fabe8a Mon Sep 17 00:00:00 2001 From: saiyam-gambhir Date: Wed, 8 Jun 2016 23:09:19 +0530 Subject: [PATCH 15/23] Removed duplicate CSS (#143) --- public/css/base.css | 3 --- 1 file changed, 3 deletions(-) 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 { From e5786f844bff18dfa3ff6330b67c9f856c5ebbf6 Mon Sep 17 00:00:00 2001 From: sthodup1 Date: Mon, 20 Jun 2016 15:13:45 -0500 Subject: [PATCH 16/23] Update React Dependency to 15.1.0 --- public/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index a76aaada..ec158df2 100644 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,8 @@ React Tutorial - - + + From 2f565db733f7614d19012f029a52f65d294b7db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Fri, 1 Jul 2016 12:29:47 -0700 Subject: [PATCH 17/23] Update for 15.2.0 --- public/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index ec158df2..1ce8900c 100644 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,8 @@ React Tutorial - - + + From 08115a6ec2df124bb03cc04974f2c5b9b290804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 2 Aug 2016 13:50:54 -0700 Subject: [PATCH 18/23] Use npmcdn (#152) --- public/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index 1ce8900c..5af72a45 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,11 @@ React Tutorial - - - - - + + + + +
From ddc30f08e010ca1401c7c9ef8f753c0749dbc499 Mon Sep 17 00:00:00 2001 From: Jonathan Herbert Date: Sat, 20 Aug 2016 20:00:30 -0400 Subject: [PATCH 19/23] Only Read Comments File On Comments Route (#154) --- server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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[] = [ From 7d0728e6d9011658420b7b30463edb2163577a15 Mon Sep 17 00:00:00 2001 From: Mike Sukmanowsky Date: Mon, 29 Aug 2016 20:08:11 -0400 Subject: [PATCH 20/23] Set debug=True flag for Flask server (#156) --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index fad15a66..03c6213d 100644 --- a/server.py +++ b/server.py @@ -41,4 +41,4 @@ def comments_handler(): if __name__ == '__main__': - app.run(port=int(os.environ.get("PORT", 3000))) + app.run(port=int(os.environ.get("PORT", 3000)), debug=True) From 35b5c0c77c0c5e4b159f78a85a66110086aaddfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Dani=C4=87?= Date: Tue, 30 Aug 2016 19:31:59 +0200 Subject: [PATCH 21/23] Use unpkg instead of npmcdn (#157) npmcdn.com is moving to unpkg.com and these links will eventually switch to 301. Better to switch to unpkg right away. https://twitter.com/mjackson/status/770424625754939394 --- public/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index 5af72a45..ca5fb5fc 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,11 @@ React Tutorial - - - - - + + + + +
From 70f7e15f3d4b048625a712713a494f7860695255 Mon Sep 17 00:00:00 2001 From: Jisu Park Date: Wed, 7 Sep 2016 02:25:07 +0900 Subject: [PATCH 22/23] feat(babel): Bump up the babel version 5.x to 6.x (#158) --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index ca5fb5fc..b88096b6 100644 --- a/public/index.html +++ b/public/index.html @@ -7,7 +7,7 @@ - + From ec8d845a8a361abf86c11af2d693150697ef858a Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Mon, 3 Oct 2016 11:06:17 -0700 Subject: [PATCH 23/23] remarkable 1.7.1 --- comments.json | 17 ++++++++++++++++- public/index.html | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) 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/public/index.html b/public/index.html index b88096b6..eb201204 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@ - +