-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
40 lines (35 loc) · 1.13 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
#!/usr/bin/env node
/**
* Server module exports method returning new instance of app.
*
* @param {Object} params - compound/express webserver initialization params.
* @returns CompoundJS powered express webserver
*/
var app = module.exports = function getServerInstance(params) {
params = params || {};
// specify current dir as default root of server
params.root = params.root || __dirname;
return require('compound').createServer(params);
};
module.exports.init = function(c) {
// setup co-docs
c.once('ready', function() {
var app = module.exports();
c = c.parent || c;
c.injectMiddlewareAt(1, c.app.get('docs route') || '/docs', app);
app.parent = c.app;
app.route = c.app.get('docs route') || '/docs';
app.emit('mount', c.app);
});
};
if (!module.parent) {
var port = process.env.PORT || 3000;
var host = process.env.HOST || '0.0.0.0';
var server = app();
server.listen(port, host, function () {
console.log(
'Compound server listening on %s:%d within %s environment',
host, port, server.set('env')
);
});
}