-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (34 loc) · 1.3 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* react-hybrid - express server.
* @see http://expressjs.com/4x/api.html
*/
var express = require('express'),
serveStatic = require('serve-static'),
errorHandler = require('errorhandler'),
path = require('path');
var app = express();
// For openshift.
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 7000);
// Static file server.
app.use(serveStatic(path.join(__dirname, 'public')));
// Required to support JSON-encoded bodies
//app.use(express.json());
// TODO Check for process.env.NODE_ENV === 'development'
app.use(errorHandler());
// Load routes, passing app
// TODO Hecate?
var indexRoute = require('./routes/index');
// Bind routes
// Test routes.
app.route('/').get(indexRoute.helloReact);
app.route('/mirror/:inputString').get(indexRoute.mirror);
// React routes.
// e.g. http://localhost:7000/hello/Jupiter
app.route('/hello/:title').get(indexRoute.helloReact);
// e.g. http://localhost:7000/helloPlanets/Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune
app.route('/helloPlanets').get(indexRoute.helloPlanets);
app.route('/helloPlanets/:planets').get(indexRoute.helloPlanets);
// @see http://stackoverflow.com/questions/17696801/express-js-app-listen-vs-server-listen
app.listen(app.get('port'), function () {
console.log('HTTP server listening on: http://localhost:' + app.get('port'));
});