-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
116 lines (108 loc) · 2.34 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const amqp = require('amqplib')
const hapi = require('hapi')
const StatsD = require('hot-shots')
const env = require('./lib/env')
require('./lib/rollbar')
;(async () => {
const statsdClient = new StatsD({
host: env.STATSD_HOST,
prefix: 'hooks.',
globalTags: [env.NODE_ENV]
})
const server = new hapi.Server({
debug: {
log: ['error', 'requested'],
request: ['error', 'requested', 'request']
}
})
const conn = await amqp.connect(env.AMQP_URL)
const channel = await conn.createChannel()
await channel.assertQueue(env.QUEUE_NAME, {
maxPriority: 5
})
server.connection({
port: env.PORT
})
server.route({
method: 'GET',
path: '/',
handler: (request, reply) => reply('OK').type('text/plain')
})
await server.register([{
register: require('./lib/github-event'),
options: {
env,
channel
}
}, {
register: require('./lib/npm-event'),
options: {
env,
channel
}
}, {
register: require('./lib/stripe-event'),
options: {
env,
channel
}
}, {
register: require('./lib/reset-event'),
options: {
env,
channel
}
}, {
register: require('./lib/sync-event'),
options: {
env,
channel
}
}, {
register: require('./lib/update-node-event'),
options: {
env,
channel
}
}, {
register: require('./lib/deprecate-node-event'),
options: {
env,
channel
}
}, {
register: require('good'),
options: {
reporters: {
myConsoleReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{
log: '*',
response: '*'
}]
},
{
module: 'good-console'
},
'stdout']
}
}
}])
if (env.IS_ENTERPRISE && env.NEXUS_SECRET && env.NEXUS_URL && env.NEXUS_REPOSITORY && env.NEXUS_INSTALLATION) {
await server.register({
register: require('./lib/nexus-event'),
options: {
env,
channel
}
})
}
server.on('response', (request, reply) => {
statsdClient.increment(`status_code.${request.response.statusCode}`)
statsdClient.timing('response_time', Date.now() - request.info.received)
})
await server.start()
console.log('server running', server.info.uri)
})()