Skip to content

Commit cfd3b70

Browse files
committed
Fix #11: EACCES on linux and EADDRINUSE
Fixes a brutal crash in case of address 443 or 80 already in use on the machine and if the script is not runned under sudo on linux. The script exit, but writing an error message and a tip on how to resolve. Update README consequently. Upgrade minimum node version to 8.
1 parent c626ab8 commit cfd3b70

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ language: node_js
66
node_js:
77
- node
88
- 10
9-
- 7.6
9+
- 8
1010
after_success: npm run coveralls

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ Checkout the updated list [here](https://github.com/FiloSottile/mkcert/blob/mast
7979

8080
## Troubleshooting
8181
### Node.js version
82-
https-localhost requires Node.js 7.6 or higher.
82+
https-localhost requires Node.js 8 or higher.
8383
<sub>If you need compatibility with previously Node.js versions let me know, I'll try to rearrange the code.</sub>
8484

8585
### root required
8686
- **At first run** this tool generate a trusted certificate. The sudo password may be required. If you cannot provide the sudo password generate a `localhost.key` and `localhost.crt` and specify its path with `CERT_PATH=/diractory/containing/certificates/ serve ~/myproj`.
8787
- **At each run** the password may be required to run the server on port 443 and 80. To avoid the script ask for password specify a different port number: `PORT=4433 serve ~/myproj`.
8888

89+
### EACCES
90+
Run with sudo to use the default ports 443 and 80. You can also change port with: `PORT=4433 serve ~/myproj`.
91+
92+
### EADDRINUSE
93+
Another service on your machine is using port 443 or port 80. Stop it or change port with `PORT=4433 serve ~/myproj`.
94+
8995
### RangeError
9096
```
9197
RangeError: Invalid typed array length: -4095

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,25 @@ if (require.main === module) {
8484
if (!process.env.PORT) app.redirect()
8585
}
8686

87+
/* istanbul ignore next: cannot be tested */
88+
process.on("uncaughtException", function(err) {
89+
switch (err.errno) {
90+
case "EACCES":
91+
console.error(
92+
"EACCES: run as administrator to use the default ports 443 and 80. " +
93+
"You can also change port with: `PORT=4433 serve ~/myproj`.")
94+
break
95+
case "EADDRINUSE":
96+
console.error("EADDRINUSE: another service on your machine is using " +
97+
"port 443 or port 80.\nStop it or change port with:" +
98+
"`PORT=4433 serve ~/myproj`.")
99+
break
100+
default:
101+
console.error("Unexpected error " + err.errno + ":\n\n" + err)
102+
break
103+
}
104+
process.exit(1)
105+
})
106+
87107
// export as module
88108
module.exports = createServer

0 commit comments

Comments
 (0)