diff --git a/README.md b/README.md index b7517b72..c9107339 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is the React comment box example from [the React tutorial](http://facebook. ## To use -There are several simple server implementations included. They all serve static files from `public/` and handle requests to `comments.json` to fetch or add data. Start a server with one of the following: +There are several simple server implementations included. They all serve static files from `public/` and handle requests to `comments` to fetch or add data. Start a server with one of the following: ### Node diff --git a/public/scripts/example.js b/public/scripts/example.js index c547e038..f3e32b18 100644 --- a/public/scripts/example.js +++ b/public/scripts/example.js @@ -120,6 +120,6 @@ var CommentForm = React.createClass({ }); React.render( - , + , document.getElementById('content') ); diff --git a/server.go b/server.go index cba31fd9..88a4ace0 100644 --- a/server.go +++ b/server.go @@ -89,7 +89,7 @@ func main() { if port == "" { port = "3000" } - http.HandleFunc("/comments.json", handleComments) + http.HandleFunc("/comments", 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 index fd4b81dd..e7888b84 100644 --- a/server.js +++ b/server.js @@ -22,14 +22,14 @@ 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) { +app.get('/comments', 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) { +app.post('/comments', function(req, res) { fs.readFile('comments.json', function(err, data) { var comments = JSON.parse(data); comments.push(req.body); diff --git a/server.php b/server.php index e140ea83..af90625d 100644 --- a/server.php +++ b/server.php @@ -21,7 +21,7 @@ function routeRequest() case '/': echo file_get_contents('./public/index.html'); break; - case '/comments.json': + case '/comments': if($_SERVER['REQUEST_METHOD'] === 'POST') { $commentsDecoded = json_decode($comments, true); $commentsDecoded[] = ['author' => $_POST['author'], diff --git a/server.py b/server.py index 730e39b3..e39662cf 100644 --- a/server.py +++ b/server.py @@ -15,7 +15,7 @@ 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']) +@app.route('/comments', methods=['GET', 'POST']) def comments_handler(): with open('comments.json', 'r') as file: diff --git a/server.rb b/server.rb index 18099ae5..afec6de9 100644 --- a/server.rb +++ b/server.rb @@ -18,7 +18,7 @@ root = File.expand_path './public' server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root -server.mount_proc '/comments.json' do |req, res| +server.mount_proc '/comments' do |req, res| comments = JSON.parse(File.read('./comments.json')) if req.request_method == 'POST'