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

Skip to content

Commit a91501d

Browse files
committed
Merge pull request reactjs#45 from freeformz/heroku_button
Heroku button
2 parents cbe73b7 + e915760 commit a91501d

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
2+
13
# React Tutorial
24

35
This is the React comment box example from [the React tutorial](http://facebook.github.io/react/docs/tutorial.html).

app.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "React Tutorial Server",
3+
"description": "Code from the React tutorial",
4+
"keywords": [ "react", "reactjs", "tutorial" ],
5+
"repository": "https://github.com/reactjs/react-tutorial",
6+
"website": "http://facebook.github.io/react/docs/tutorial.html",
7+
"success_url": "/",
8+
"env" : {
9+
"BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-nodejs.git"
10+
}
11+
}
12+

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"bugs": {
2727
"url": "https://github.com/reactjs/react-tutorial/issues"
2828
},
29-
"homepage": "https://github.com/reactjs/react-tutorial"
29+
"homepage": "https://github.com/reactjs/react-tutorial",
30+
"engines" : {
31+
"node" : "0.12.x"
32+
}
3033
}

server.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
8585
}
8686

8787
func main() {
88+
port := os.Getenv("PORT")
89+
if port == "" {
90+
port = "3000"
91+
}
8892
http.HandleFunc("/comments.json", handleComments)
8993
http.Handle("/", http.FileServer(http.Dir("./public")))
90-
log.Println("Server started: http://localhost:3000")
91-
log.Fatal(http.ListenAndServe(":3000", nil))
94+
log.Println("Server started: http://localhost:" + port)
95+
log.Fatal(http.ListenAndServe(":"+port, nil))
9296
}

server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var express = require('express');
1616
var bodyParser = require('body-parser');
1717
var app = express();
1818

19+
app.set('port', (process.env.PORT || 3000));
20+
1921
app.use('/', express.static(path.join(__dirname, 'public')));
2022
app.use(bodyParser.json());
2123
app.use(bodyParser.urlencoded({extended: true}));
@@ -39,6 +41,7 @@ app.post('/comments.json', function(req, res) {
3941
});
4042
});
4143

42-
app.listen(3000);
4344

44-
console.log('Server started: http://localhost:3000/');
45+
app.listen(app.get('port'), function() {
46+
console.log('Server started: http://localhost:' + app.get('port') + '/');
47+
});

server.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
isset($_SERVER['argv'][0]) && $_SERVER['argv'][0] === 'server.php';
44

55
if($scriptInvokedFromCli) {
6-
echo 'starting server on port 3000' . PHP_EOL;
7-
exec('php -S localhost:3000 -t public server.php');
6+
$port = getenv('PORT');
7+
if (empty($port)) {
8+
$port = "3000";
9+
}
10+
11+
echo 'starting server on port '. $port . PHP_EOL;
12+
exec('php -S localhost:'. $port . ' -t public server.php');
813
} else {
914
return routeRequest();
1015
}

server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1010

1111
import json
12+
import os
1213
from flask import Flask, Response, request
1314

1415
app = Flask(__name__, static_url_path='', static_folder='public')
@@ -29,4 +30,4 @@ def comments_handler():
2930
return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})
3031

3132
if __name__ == '__main__':
32-
app.run(port=3000)
33+
app.run(port=int(os.environ.get("PORT",3000)))

server.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
require 'webrick'
1212
require 'json'
1313

14-
puts 'Server started: http://localhost:3000/'
14+
port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i
15+
16+
puts "Server started: http://localhost:#{port}/"
1517

1618
root = File.expand_path './public'
17-
server = WEBrick::HTTPServer.new :Port => 3000, :DocumentRoot => root
19+
server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root
1820

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

0 commit comments

Comments
 (0)