-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
60 lines (46 loc) · 1.17 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
/*
ard-eventhub
by SWR Audio Lab
*/
// enable tracing
require('../utils/tracer')
// load node utils
const compression = require('compression')
const express = require('express')
// load utils
const logger = require('../utils/logger')
// load config
const config = require('../../config')
// set up express server
const server = express()
// add debugging information to all headers
server.use((req, res, next) => {
// add service information
res.set('x-service', config.userAgent)
// log all headers in local mode
if (config.isLocal) {
const logHeaders = {
...req.headers,
authorization: 'hidden',
}
logger.log({
level: 'debug',
message: 'middleware logging',
source: 'DEV',
data: { logHeaders, path: req.path },
})
}
// continue with normal workflow
next()
})
// import router
server.use('/', require('./router'))
// start express server
server.use(compression())
server.disable('x-powered-by')
server.listen(config.port)
if (config.isLocal) {
console.log(`${config.serviceName} (v${config.version}) is running at: ${config.serviceUrl}`)
console.log(` - OpenAPI documentation: ${config.serviceUrl}/openapi`)
}
module.exports = server