-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (39 loc) · 1.02 KB
/
server.js
File metadata and controls
42 lines (39 loc) · 1.02 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
process.on('uncaughtException', function(err) {
console.error('Caught exception: ' + err)
console.error(err.stack)
})
const { att } = require('./app')
let { server, app } = att()
function onError(error) {
if (error.syscall !== 'listen') {
throw error
}
const port = process.env.ATT_PORT
const bind = typeof port === 'string'
? `Pipe ${port}`
: `Port ${port}`
switch (error.code) {
case 'EACCES':
console.info(`${bind} correr en otro puerto, este puerto requiere permisos de root`)
process.exit(1)
break
case 'EADDRINUSE':
console.info(`${bind} el puerto ya esta en uso client`)
process.exit(1)
break
default:
throw error
}
}
function onListening() {
const addr = server.address()
const bind = typeof addr === 'string'
? `Pipe ${addr}`
: `Port ${addr.port}`
if (process.env.NODE_ENV !== 'testing') {
console.info(`server corriendo en ${bind}`)
}
}
server.on('error', onError)
server.on('listening', onListening)
server.listen(app.get('port'))