mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: correct socket address in use error message
This commit is contained in:
parent
b675a0623b
commit
2eb1965357
@ -95,15 +95,16 @@ export default class Listener {
|
||||
|
||||
// Use better error message
|
||||
if (addressInUse) {
|
||||
error.message = `Address \`${this.host}:${this.port}\` is already in use.`
|
||||
}
|
||||
const address = this.socket || `${this.host}:${this.port}`
|
||||
error.message = `Address \`${address}\` is already in use.`
|
||||
|
||||
// Listen to a random port on dev as a fallback
|
||||
if (addressInUse && this.dev && this.port !== '0') {
|
||||
consola.warn(error.message)
|
||||
consola.info('Trying a random port...')
|
||||
this.port = '0'
|
||||
return this.close().then(() => this.listen())
|
||||
// Listen to a random port on dev as a fallback
|
||||
if (this.dev && !this.socket && this.port !== '0') {
|
||||
consola.warn(error.message)
|
||||
consola.info('Trying a random port...')
|
||||
this.port = '0'
|
||||
return this.close().then(() => this.listen())
|
||||
}
|
||||
}
|
||||
|
||||
// Throw error
|
||||
|
@ -330,6 +330,15 @@ describe('server: listener', () => {
|
||||
expect(() => listener.serverErrorHandler(addressInUse)).toThrow('Address `localhost:3000` is already in use.')
|
||||
})
|
||||
|
||||
test('should throw address in use error for socket', () => {
|
||||
const listener = new Listener({})
|
||||
listener.socket = 'nuxt.socket'
|
||||
|
||||
const addressInUse = new Error()
|
||||
addressInUse.code = 'EADDRINUSE'
|
||||
expect(() => listener.serverErrorHandler(addressInUse)).toThrow('Address `nuxt.socket` is already in use.')
|
||||
})
|
||||
|
||||
test('should fallback to a random port in address in use error', async () => {
|
||||
const listener = new Listener({ dev: true })
|
||||
listener.host = 'localhost'
|
||||
|
Loading…
Reference in New Issue
Block a user