This repository has been archived by the owner on Aug 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (47 loc) · 1.58 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
47
48
49
50
51
52
53
54
process.on('uncaughtException', handleError);
function handleError(err) {
console.error((new Date).toUTCString() + ' uncaughtException:', err.message);
console.error(err.stack);
process.exit(1);
}
var path = require('path');
var appNodeModules = path.join(__dirname, 'pipeline_modules');
console.log('pipeline modules path:', appNodeModules);
require('app-module-path').addPath(appNodeModules);
var fs = require('fs');
var log = require('pl-log');
var config = require('pl-config');
var websiteName = process.env.PIPELINE_ROLE;
var websitePath = path.join(__dirname, 'websites', websiteName);
console.log('staring website:', websitePath);
if (!fs.existsSync(websitePath)) {
console.warn('this is a worker role');
require('http').createServer(function (req, res) {
return res.end('hello from ' + process.env.PIPELINE_ROLE + ' worker');
}).listen(process.env.PORT);
}
else {
var app = require(websitePath);
if (process.env.USE_ANODE_LOGGING !== 'false') {
log.init({
domain: process.env.COMPUTERNAME || '',
instanceId: log.getInstanceId(),
app: websiteName,
level: config.log.level,
transporters: config.log.transporters
},
function(err) {
if (err) return handleError(err);
console.log('starting %s server...', websiteName);
return runWebsite();
});
}
else
return runWebsite();
function runWebsite() {
var server = app.listen(app.get('port'), function(err) {
if (err) return handleError(err);
console.log('%s server listening on port %s', websiteName, server.address().port);
});
}
}