mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-12-04 14:23:35 +01:00
Output webhook endpoints at startup
This commit is contained in:
parent
f7567cd2f9
commit
5ac148cf0f
1 changed files with 22 additions and 2 deletions
|
@ -130,9 +130,25 @@ module.exports = (logger, config, xmpp) => {
|
|||
logger.error('Error', error)
|
||||
})
|
||||
|
||||
// get IP v4 addresses and prepare endpoints for output
|
||||
let addresses = []
|
||||
const networkInterfaces = require('os').networkInterfaces()
|
||||
for (let ifaceName in networkInterfaces) {
|
||||
addresses = addresses.concat(networkInterfaces[ifaceName].reduce((add, iface) => {
|
||||
if (iface['family'] === 'IPv4') {
|
||||
add.push(iface['address'])
|
||||
}
|
||||
return add
|
||||
}, []))
|
||||
}
|
||||
|
||||
// start HTTP listener
|
||||
const httpServer = http.createServer(webhook).listen(port, () => {
|
||||
logger.info(`Listening webhooks on http://localhost:${port}${config.listener.path}`)
|
||||
let endpoints = `http://localhost:${port}${config.listener.path}`
|
||||
addresses.forEach(address => {
|
||||
endpoints += ` http://${address}:${port}${config.listener.path}`
|
||||
})
|
||||
logger.info(`Listening webhooks on ${endpoints}`)
|
||||
})
|
||||
|
||||
// start HTTPS listener
|
||||
|
@ -155,7 +171,11 @@ module.exports = (logger, config, xmpp) => {
|
|||
cert: fs.readFileSync(config.listener.ssl.certPath)
|
||||
}
|
||||
https.createServer(credentials, webhook).listen(portSsl, () => {
|
||||
logger.info(`Listening webhooks on https://localhost:${portSsl}${config.listener.path}`)
|
||||
let endpoints = `https://localhost:${portSsl}${config.listener.path}`
|
||||
addresses.forEach(address => {
|
||||
endpoints += ` https://${address}:${portSsl}${config.listener.path}`
|
||||
})
|
||||
logger.info(`Listening webhooks on ${endpoints}`)
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error(`Can not read certificate: ${err.message}`)
|
||||
|
|
Loading…
Reference in a new issue