forked from volumio/volumio3-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (73 loc) · 2.59 KB
/
index.js
File metadata and controls
85 lines (73 loc) · 2.59 KB
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
var path = require('path')
require('dotenv').config({path: path.join(__dirname, '.env')})
var execSync = require('child_process').execSync
var expressInstance = require('./http/index.js')
var expressApp = expressInstance.app
var newWizardDir = '/volumio/http/wizard'
global.metrics = {
start: {},
time: (label) => {
metrics.start[label] = process.hrtime()
},
end: {},
log: (label) => {
metrics.end[label] = process.hrtime(metrics.start[label])
console.log(
`\u001b[34m [Metrics] \u001b[39m ${label}: \u001b[31m ${metrics.end[label][0]}s ${(
metrics.end[label][1] / 1000000
).toFixed(2)}ms \u001b[39m`
)
},
}
// metrics.start.WebUI = process.hrtime();
metrics.time('WebUI')
// Using port 3000 for the debug interface
expressApp.set('port', 3000)
var httpServer = expressApp.listen(expressApp.get('port'), function () {
console.log('Express server listening on port ' + httpServer.address().port)
metrics.log('WebUI')
})
var albumart = require(path.join(__dirname, '/app/plugins/miscellanea/albumart/albumart.js'))
albumart.setFolder('/data/albumart')
expressApp.get('/albumart', albumart.processExpressRequest)
expressApp.get('/tinyart/*', albumart.processExpressRequestTinyArt)
expressApp.get('/albumartd', albumart.processExpressRequestDirect)
expressApp.use(function (err, req, res, next) {
/**
* Replace with Winston logging
**/
console.log('An internal error occurred while serving an albumart. Details: ' + err.stack)
/**
* Sending back error code 500
**/
res.sendFile(path.join(__dirname, '/app/plugins/miscellanea/albumart/default.png'))
})
var commandRouter = new (require('./app/index.js'))(httpServer)
expressApp.get('/?*', function (req, res) {
var userAgent = req.get('user-agent')
if (process.env.SHOW_NEW_WIZARD === 'true') {
res.sendFile(path.join(newWizardDir, 'index.html'))
} else {
res.sendFile(path.join(process.env.VOLUMIO_ACTIVE_UI_PATH, 'index.html'))
}
})
process.on('uncaughtException', (error) => {
console.log(
'|||||||||||||||||||||||| WARNING: FATAL ERROR |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'
)
console.log(error)
console.log(
'|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'
)
var errorMessage
if (error.message !== undefined) {
errorMessage = error.message
} else {
errorMessage = 'Unknown'
}
process.env.VOLUMIO_SYSTEM_STATUS = 'error'
execSync('/usr/bin/node /volumio/crashreport.js "' + errorMessage + '"')
if (process.env.EXIT_ON_EXCEPTION === 'true') {
process.exit(1)
}
})