Show all ipv4 addresses when server is running on unspecified address

This commit is contained in:
pimlie 2017-11-21 13:27:17 +01:00
parent 9bf73b0b5a
commit 4eff3b9d27

View File

@ -120,7 +120,28 @@ export default class Nuxt {
const _host = host === '0.0.0.0' ? 'localhost' : host
// eslint-disable-next-line no-console
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}`))
if (host === '0.0.0.0') {
const ifaces = require('os').networkInterfaces()
Object.keys(ifaces).forEach((ifName) => {
let ifAliasNum = 0
let ifAlias = ''
ifaces[ifName].forEach((iface, index) => {
if (iface.family === 'IPv4' && iface.internal === false) {
if (ifAliasNum > 0) {
ifAlias = `:${ifAliasNum}`
}
// eslint-disable-next-line no-console
console.log(chalk.bgGreen.black(` OPEN (${ifName}${ifAlias}) `) + chalk.green(` http://${iface.address}:${port}`))
ifAliasNum++
}
})
})
}
// eslint-disable-next-line no-console
console.log('\n')
// Close server on nuxt close
this.hook('close', () => new Promise((resolve, reject) => {