- );
- }
-});
-
-var CommentList = React.createClass({
- render: function() {
- var commentNodes = this.props.data.map(function(comment, index) {
- return (
- // `key` is a React-specific concept and is not mandatory for the
- // purpose of this tutorial. if you're curious, see more here:
- // http://facebook.github.io/react/docs/multiple-components.html#dynamic-children
-
- {comment.text}
-
- );
- });
- return (
-
- {commentNodes}
-
- );
- }
-});
-
-var CommentForm = React.createClass({
- handleSubmit: function(e) {
- e.preventDefault();
- var author = React.findDOMNode(this.refs.author).value.trim();
- var text = React.findDOMNode(this.refs.text).value.trim();
- if (!text || !author) {
- return;
- }
- this.props.onCommentSubmit({author: author, text: text});
- React.findDOMNode(this.refs.author).value = '';
- React.findDOMNode(this.refs.text).value = '';
- },
- render: function() {
- return (
-
- );
- }
-});
-
-React.render(
- ,
- document.getElementById('content')
-);
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 632a1efa..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-Flask==0.10.1
diff --git a/server.go b/server.go
deleted file mode 100644
index cba31fd9..00000000
--- a/server.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package main
-
-import (
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- "sync"
-)
-
-type comment struct {
- Author string `json:"author"`
- Text string `json:"text"`
-}
-
-const dataFile = "./comments.json"
-
-var commentMutex = new(sync.Mutex)
-
-// Handle comments
-func handleComments(w http.ResponseWriter, r *http.Request) {
- // Since multiple requests could come in at once, ensure we have a lock
- // around all file operations
- commentMutex.Lock()
- defer commentMutex.Unlock()
-
- // Stat the file, so we can find it's current permissions
- fi, err := os.Stat(dataFile)
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to stat the data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- // Read the comments from the file.
- commentData, err := ioutil.ReadFile(dataFile)
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to read the data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- switch r.Method {
- case "POST":
- // Decode the JSON data
- comments := make([]comment, 0)
- if err := json.Unmarshal(commentData, &comments); err != nil {
- http.Error(w, fmt.Sprintf("Unable to Unmarshal comments from data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- // Add a new comment to the in memory slice of comments
- comments = append(comments, comment{Author: r.FormValue("author"), Text: r.FormValue("text")})
-
- // Marshal the comments to indented json.
- commentData, err = json.MarshalIndent(comments, "", " ")
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to marshal comments to json: %s", err), http.StatusInternalServerError)
- return
- }
-
- // Write out the comments to the file, preserving permissions
- err := ioutil.WriteFile(dataFile, commentData, fi.Mode())
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to write comments to data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- w.Header().Set("Content-Type", "application/json")
- w.Header().Set("Cache-Control", "no-cache")
- io.Copy(w, bytes.NewReader(commentData))
-
- case "GET":
- w.Header().Set("Content-Type", "application/json")
- w.Header().Set("Cache-Control", "no-cache")
- // stream the contents of the file to the response
- io.Copy(w, bytes.NewReader(commentData))
-
- default:
- // Don't know the method, so error
- http.Error(w, fmt.Sprintf("Unsupported method: %s", r.Method), http.StatusMethodNotAllowed)
- }
-}
-
-func main() {
- port := os.Getenv("PORT")
- if port == "" {
- port = "3000"
- }
- http.HandleFunc("/comments.json", handleComments)
- http.Handle("/", http.FileServer(http.Dir("./public")))
- log.Println("Server started: http://localhost:" + port)
- log.Fatal(http.ListenAndServe(":"+port, nil))
-}
diff --git a/server.js b/server.js
deleted file mode 100644
index fd4b81dd..00000000
--- a/server.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * This file provided by Facebook is for non-commercial testing and evaluation purposes only.
- * Facebook reserves all rights not expressly granted.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-var fs = require('fs');
-var path = require('path');
-var express = require('express');
-var bodyParser = require('body-parser');
-var app = express();
-
-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.get('/comments.json', function(req, res) {
- 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) {
- var comments = JSON.parse(data);
- comments.push(req.body);
- 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));
- });
- });
-});
-
-
-app.listen(app.get('port'), function() {
- console.log('Server started: http://localhost:' + app.get('port') + '/');
-});
diff --git a/server.php b/server.php
deleted file mode 100644
index e140ea83..00000000
--- a/server.php
+++ /dev/null
@@ -1,41 +0,0 @@
- $_POST['author'],
- 'text' => $_POST['text']];
-
- $comments = json_encode($commentsDecoded, JSON_PRETTY_PRINT);
- file_put_contents('comments.json', $comments);
- }
- header('Content-Type: application/json');
- header('Cache-Control: no-cache');
- echo $comments;
- break;
- default:
- return false;
- }
-}
-
diff --git a/server.py b/server.py
deleted file mode 100644
index 730e39b3..00000000
--- a/server.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# This file provided by Facebook is for non-commercial testing and evaluation purposes only.
-# Facebook reserves all rights not expressly granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-import json
-import os
-from flask import Flask, Response, request
-
-app = Flask(__name__, static_url_path='', static_folder='public')
-app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))
-
-@app.route('/comments.json', methods=['GET', 'POST'])
-def comments_handler():
-
- 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:
- file.write(json.dumps(comments, indent=4, separators=(',', ': ')))
-
- return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})
-
-if __name__ == '__main__':
- app.run(port=int(os.environ.get("PORT",3000)))
diff --git a/server.rb b/server.rb
deleted file mode 100644
index 18099ae5..00000000
--- a/server.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# This file provided by Facebook is for non-commercial testing and evaluation purposes only.
-# Facebook reserves all rights not expressly granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-require 'webrick'
-require 'json'
-
-port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i
-
-puts "Server started: http://localhost:#{port}/"
-
-root = File.expand_path './public'
-server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root
-
-server.mount_proc '/comments.json' do |req, res|
- 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 => ' '))
- end
-
- # always return json
- res['Content-Type'] = 'application/json'
- res['Cache-Control'] = 'no-cache'
- res.body = JSON.generate(comments)
-end
-
-trap 'INT' do server.shutdown end
-
-server.start
diff --git a/server/comments.json b/server/comments.json
new file mode 100644
index 00000000..c45642d0
--- /dev/null
+++ b/server/comments.json
@@ -0,0 +1,19 @@
+[
+ {
+ "id": "1",
+ "author": "Pete Hunt",
+ "text": "Hey there!"
+ },
+ {
+ "author": "test",
+ "text": "teset"
+ },
+ {
+ "author": "Giuseppe",
+ "text": "React is awesome"
+ },
+ {
+ "author": "dsf",
+ "text": "dfsf"
+ }
+]
\ No newline at end of file
diff --git a/server/server.js b/server/server.js
new file mode 100644
index 00000000..a94ea895
--- /dev/null
+++ b/server/server.js
@@ -0,0 +1,39 @@
+var fs = require("fs");
+var path = require("path");
+var express = require("express");
+var bodyParser = require("body-parser");
+var app = express();
+
+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}));
+
+var commentsFile = path.join(__dirname, "comments.json");
+
+app.get("/comments.json", function(req, res) {
+ fs.readFile(commentsFile, function(err, data) {
+ console.log(err, data);
+ res.setHeader("Content-Type", "application/json");
+ res.send(data);
+ });
+});
+
+app.post("/comments.json", function(req, res) {
+ fs.readFile(commentsFile, function(err, data) {
+ var comments = JSON.parse(data);
+ comments.push(req.body);
+ fs.writeFile(commentsFile, JSON.stringify(comments, null, 4), function() {
+ res.setHeader("Content-Type", "application/json");
+ res.setHeader("Cache-Control", "no-cache");
+ res.send(JSON.stringify(comments));
+ });
+ });
+});
+
+
+app.listen(app.get("port"), function() {
+ console.log("Server started: http://localhost:" + app.get("port") + "/");
+});