-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
90 lines (81 loc) · 1.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var Hapi = require('hapi');
var Fs = require('fs');
var BeaverBuild = require('./beaverbuild');
var Fetcher = require('./fetcher');
var S3 = require('./s3');
var rimraf = require('rimraf')
var Good = require('good');
var JobQueue = require('./job-queue');
var server;
if(process.env.PORT) {
// Azure init
server = new Hapi.Server();
server.connection({
port: process.env.PORT
});
}
else {
// Create localhost server
server = new Hapi.Server();
server.connection({
port: 8000
});
}
// Set up views
server.views({
engines: {
html: require('handlebars')
},
path: './views',
layoutPath: './views/layout',
helpersPath: './views/helpers',
partialsPath: './views/partials',
isCached: false //Remove in production!
});
// Add route for rendering home page
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.view('index');
}
});
// Add route for receiving webhook requests
server.route({
method: 'POST',
path: '/',
handler: function (request, reply) {
server.log('Request:', request);
server.log('Webhook request received', '');
server.log('Sending webhook payload to job queue...')
JobQueue.SendMessage(request.payload.payload, function (err, data) {
server.log('Done sending webhook payload to job queue', data);
if(err) {
server.log('Job queue error:', err);
}
});
reply({
greeting: 'Thanks Github!'
});
}
});
var options = {
opsInterval: 1000,
reporters: [{
reporter: require('good-console'),
args:[{ log: '*', response: '*' }]
}]
};
server.register({
register: require('good'),
options: options
}, function (err) {
if (err) {
console.error(err);
}
else {
server.start(function () {
console.info('Job Manager server started at ' + server.info.uri);
});
}
});