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

Don't start develop server if port in use #335

Merged
merged 1 commit into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 20 additions & 5 deletions lib/utils/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,27 @@ module.exports = (program) => {

server.start((e) => {
if (e) {
console.log(e)
if (e.code === 'EADDRINUSE') {
const finder = require('process-finder')
finder.find({ elevate: false, port: program.port }, (startErr, pids) => {
const msg =
`We were unable to start Gatsby on port ${program.port} as there's already a process
listening on that port (PID: ${pids[0]}). You can either use a different port
(e.g. gatsby develop --port ${parseInt(program.port, 10) + 1}) or stop the process already listening
on your desired port.`
console.log(msg)
process.exit()
})
} else {
console.log(e)
process.exit()
}
} else {
if (program.open) {
opn(server.info.uri)
}
console.log('Listening at:', server.info.uri)
}
if (program.open) {
opn(server.info.uri)
}
return console.log('Listening at:', server.info.uri)
})
})
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"postcss-import": "^8.1.2",
"postcss-loader": "^0.9.1",
"postcss-reporter": "^1.3.3",
"process-finder": "^1.0.0",
"raw-loader": "^0.5.1",
"react": "^15.1.0",
"react-document-title": "^2.0.1",
Expand Down