-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (49 loc) · 1.87 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
// Set Debugging up:
if (process.env.NODE_ENV === 'development' && !process.env.DEBUG) {
process.env.DEBUG = '*';
}
// var path = require('path');
var debug = require('debug');
var log = debug('metal-forge');
var error = debug('metal-forge:error');
var express = require('express');
var app = express();
// Configurations
var config = require('./config.json');
var port = process.env.PORT || 8080;
var host = process.env.HOSTNAME || 'localhost';
// modules
var routes = require('routes');
var build_tasks = require('build_tasks');
if (!config.webhooks) {
error("webhooks isn't defined in `config.json`");
throw new Error("webhooks isn't defined in `config.json`");
}
app.use(routes);
var server = app.listen(port, host, function () {
'use strict';
var server_host = server.address().address;
var server_port = server.address().port;
console.log('App listening at http://%s:%s', server_host, server_port);
// Output the cURL commands for testing webhooks
Object.keys(config.webhooks).forEach(function (path) {
'use strict';
var webhook = config.webhooks[path];
var curl_parts = [
'curl -X ' + webhook.method
];
if (webhook.username && webhook.password) {
curl_parts.push('-u ' + webhook.username + ':' + webhook.password);
}
if (webhook.expected_header) {
Object.keys(webhook.expected_header).forEach(function (key) {
var element = webhook.expected_header[key];
curl_parts.push('--header "' + key + ': ' + element + '"');
});
}
curl_parts.push(server.address().address + ':' + server.address().port + '/' + config.path_to_webhook + '/' + path);
console.log('Test `' + webhook.name + '` Webhook with:\n' + curl_parts.join(' ') + '\n');
});
});
// Initialise codebase and build
build_tasks.init_build();