Skip to content
Open
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
40 changes: 20 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ if (require.main === module) {
app.serve(process.argv.length === 3 ? process.argv[2] : process.cwd())
// redirect http to https (only if https port is the default one)
if (!process.env.PORT) app.redirect()
}

/* istanbul ignore next: cannot be tested */
process.on("uncaughtException", function(err) {
switch (err.errno) {
case "EACCES":
console.error(
"EACCES: run as administrator to use the default ports 443 and 80. " +
"You can also change port with: `PORT=4433 serve ~/myproj`.")
break
case "EADDRINUSE":
console.error("EADDRINUSE: another service on your machine is using " +
"the current port.\nStop it or change port with:" +
"`PORT=4433 serve ~/myproj`.")
break
default:
console.error("Unexpected error " + err.errno + ":\n\n" + err)
break
}
process.exit(1)
})
/* istanbul ignore next: cannot be tested */
process.on("uncaughtException", function(err) {
switch (err.errno) {
case "EACCES":
console.error(
"EACCES: run as administrator to use the default ports 443 and 80. " +
"You can also change port with: `PORT=4433 serve ~/myproj`.")
break
case "EADDRINUSE":
console.error("EADDRINUSE: another service on your machine is using " +
"the current port.\nStop it or change port with:" +
"`PORT=4433 serve ~/myproj`.")
break
default:
console.error("Unexpected error " + err.errno + ":\n\n" + err)
break
}
process.exit(1)
})
}

// export as module
module.exports = createServer
16 changes: 16 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require("assert")

describe("Testing module import", () => {
it("doesn't install an uncaughtException handler when imported", () => {
const modulePath = require.resolve("../index.js")
const listenersBefore = process.listenerCount("uncaughtException")

delete require.cache[modulePath]
require(modulePath)

assert.strictEqual(
process.listenerCount("uncaughtException"),
listenersBefore
)
})
})