Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Heroku button #45

Merged
merged 8 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

# React Tutorial

This is the React comment box example from [the React tutorial](http://facebook.github.io/react/docs/tutorial.html).
Expand Down
12 changes: 12 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "React Tutorial Server",
"description": "Code from the React tutorial",
"keywords": [ "react", "reactjs", "tutorial" ],
"repository": "https://github.com/reactjs/react-tutorial",
"website": "http://facebook.github.io/react/docs/tutorial.html",
"success_url": "/",
"env" : {
"BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-nodejs.git"
}
}

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"bugs": {
"url": "https://github.com/reactjs/react-tutorial/issues"
},
"homepage": "https://github.com/reactjs/react-tutorial"
"homepage": "https://github.com/reactjs/react-tutorial",
"engines" : {
"node" : "0.12.x"
}
}
8 changes: 6 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
}

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:3000")
log.Fatal(http.ListenAndServe(":3000", nil))
log.Println("Server started: http://localhost:" + port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
7 changes: 5 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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}));
Expand All @@ -39,6 +41,7 @@ app.post('/comments.json', function(req, res) {
});
});

app.listen(3000);

console.log('Server started: http://localhost:3000/');
app.listen(app.get('port'), function() {
console.log('Server started: http://localhost:' + app.get('port') + '/');
});
9 changes: 7 additions & 2 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
isset($_SERVER['argv'][0]) && $_SERVER['argv'][0] === 'server.php';

if($scriptInvokedFromCli) {
echo 'starting server on port 3000' . PHP_EOL;
exec('php -S localhost:3000 -t public server.php');
$port = getenv('PORT');
if (empty($port)) {
$port = "3000";
}

echo 'starting server on port '. $port . PHP_EOL;
exec('php -S localhost:'. $port . ' -t public server.php');
} else {
return routeRequest();
}
Expand Down
3 changes: 2 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# 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')
Expand All @@ -29,4 +30,4 @@ def comments_handler():
return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})

if __name__ == '__main__':
app.run(port=3000)
app.run(port=int(os.environ.get("PORT",3000)))
6 changes: 4 additions & 2 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
require 'webrick'
require 'json'

puts 'Server started: http://localhost:3000/'
port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i

puts "Server started: http://localhost:#{port}/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do the same for the go server and make sure it outputs the right port?


root = File.expand_path './public'
server = WEBrick::HTTPServer.new :Port => 3000, :DocumentRoot => root
server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root

server.mount_proc '/comments.json' do |req, res|
comments = JSON.parse(File.read('./comments.json'))
Expand Down