Skip to content

Commit 2921cc4

Browse files
committed
Incremented coverage
1 parent ee95687 commit 2921cc4

4 files changed

Lines changed: 6 additions & 41 deletions

File tree

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ or from another module with `process.env.PORT = <port-number>`.
4848
If you specify a port number the http redirect to https will be disabled.
4949
You can activate the http redirect again specifying not only the PORT environment variable but also the HTTP_PORT one.
5050

51-
#### Close the server
52-
You can close the server with `app.close()`.
53-
Closing the server is an async operation, you can get notified with a promise: `app.close().then(...)`.
54-
5551
---
5652

5753
### License

index.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,23 @@ const port = process.env.PORT || 443
2121
const app = express()
2222
app.server = https.createServer(certOptions, app).listen(port)
2323

24-
// save sockets for fast close
25-
const sockets = []
26-
let nextSocketId = 0
27-
app.server.on("connection", socket => {
28-
const socketId = nextSocketId++
29-
sockets[socketId] = socket
30-
socket.on("close", () => delete sockets[socketId])
31-
})
32-
3324
// gzip compression and minify
3425
app.use(compression())
3526
app.set("json spaces", 0)
3627

3728
// redirect http to https
38-
if (port === 443 || process.env.HTTP_PORT) {
29+
if (port === 443 || process.env.HTTP_PORT)
3930
app.http = http.createServer((req, res) => {
4031
res.writeHead(301, { Location: "https://" + req.headers["host"] + req.url })
4132
res.end()
4233
}).listen(process.env.HTTP_PORT || 80)
4334

44-
app.http.on("connection", socket => {
45-
const socketId = nextSocketId++
46-
sockets[socketId] = socket
47-
socket.on("close", () => delete sockets[socketId])
48-
})
49-
}
50-
5135
// serve static files, if launched as: "node index.js <static-path>"
52-
if (require.main === module) {
53-
const staticPath = process.argv[2]
54-
app.use(express.static(staticPath || process.cwd()))
55-
}
36+
if (require.main === module)
37+
app.use(express.static(process.argv[2] || process.cwd()))
5638

5739
// ready
5840
console.info("Server running on port " + port + ".")
5941

60-
// close the app
61-
app.close = () => {
62-
const promises = [
63-
new Promise(resolve => app.http.close(resolve)),
64-
new Promise(resolve => app.server.close(resolve))
65-
]
66-
// destroy all opens
67-
for (const socketId in sockets)
68-
sockets[socketId].destroy()
69-
return Promise.all(promises).then(() => {
70-
console.info("Server closed.")
71-
})
72-
}
73-
7442
// export as module
7543
module.exports = app

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"pretest": "eslint --ignore-path .gitignore .",
88
"test": "mocha --exit",
9-
"posttest": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*.js",
9+
"posttest": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*.js --exit",
1010
"start": "node index.js"
1111
},
1212
"bin": {

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ describe("Testing https-localhost", () => {
7272
.then(res => assert(res.data === "TEST"))
7373
})
7474
it("serve static file used as standalone tool", async function() {
75-
await app.close()
75+
process.env.PORT = 4444
76+
process.env.HTTP_PORT = 8081
7677
runScript("index.js", ["test"], true)
7778
.then(process => proc = process) // eslint-disable-line no-return-assign
7879
.catch(err => console.error(err))

0 commit comments

Comments
 (0)