Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pretty message if port already in use(#927) #932

Merged
merged 10 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/next-dev
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ srv.start(argv.port)
}
})
.catch((err) => {
console.error(err)
process.exit(1)
if (err.code === 'EADDRINUSE') {
console.error(`Port ${argv.port} is already in use.\nUse \`npm run dev -- -p <some other port>\`.`)
Copy link
Contributor

@arunoda arunoda Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not 100% sure, the user will have dev NPM script for next. So, we should try to find it.
Find a NPM script with just next but not with next start or next build.

If we found it, add the message which says npm run <script name> -- -p <some other port>.
Otherwise, just don't display that.

} else {
console.error(err)
}
process.nextTick(function () { process.exit(1) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.nextTick(() => process.exit(1)) should do 😄

})
7 changes: 5 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ export default class Server {
await this.prepare()
this.http = http.createServer(this.getRequestHandler())
await new Promise((resolve, reject) => {
this.http.listen(port, (err) => {
if (err) return reject(err)
this.http.on('error', (error) => {
Copy link
Member

@timneutkens timneutkens Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.http.on('error', (error) => reject(error))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just this.http.on('error', reject)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it was a long day 😉

reject(error)
})
this.http.on('listening', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.http.on('listening', () => resolve())

resolve()
})
this.http.listen(port, () => {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can omit callback ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
}

Expand Down