-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (61 loc) · 1.69 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var express = require('express')
, rendr = require('rendr')
, app = express();
/**
* Initialize Express middleware stack.
*/
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
app.use(express.bodyParser());
/**
* In this simple example, the DataAdapter config, which specifies host, port, etc. of the API
* to hit, is written inline. In a real world example, you would probably move this out to a
* config file. Also, if you want more control over the fetching of data, you can pass your own
* `dataAdapter` object to the call to `rendr.createServer()`.
*/
var dataAdapterConfig = {
'default': {
host: 'api.github.com',
protocol: 'https'
},
'travis-ci': {
host: 'api.travis-ci.org',
protocol: 'https'
}
};
/**
* Initialize our Rendr server.
*/
var server = rendr.createServer({
dataAdapterConfig: dataAdapterConfig
});
/**
* To mount Rendr, which owns its own Express instance for better encapsulation,
* simply add `server` as a middleware onto your Express app.
* This will add all of the routes defined in your `app/routes.js`.
* If you want to mount your Rendr app onto a path, you can do something like:
*
* app.use('/my_cool_app', server);
*/
app.use(server);
/**
* Start the Express server.
*/
function start(){
var port = process.env.PORT || 3030;
app.listen(port);
console.log("server pid %s listening on port %s in %s mode",
process.pid,
port,
app.get('env')
);
}
/**
* Only start server if this script is executed, not if it's require()'d.
* This makes it easier to run integration tests on ephemeral ports.
*/
if (require.main === module) {
start();
}
exports.app = app;