Skip to content

Commit 560f3b6

Browse files
committedSep 3, 2018
v1.1.1 Lint
1 parent e8b8417 commit 560f3b6

File tree

7 files changed

+1414
-99
lines changed

7 files changed

+1414
-99
lines changed
 

‎.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"extends": "standard",
3+
//"extends": "strongloop",
4+
//"extends": "eslint:recommended",
5+
"env": {
6+
"node": true,
7+
"es6": true,
8+
"mocha": true
9+
},
10+
"parserOptions": {
11+
"ecmaVersion": 8
12+
},
13+
"rules": {
14+
"semi": ["warn", "never"],
15+
"quotes": ["warn", "double"],
16+
"comma-dangle": ["warn", "never"],
17+
"space-before-function-paren": ["warn", "never"],
18+
"curly": ["warn", "multi"],
19+
"max-len": ["error", { "code": 80, "tabWidth": 2 }],
20+
"quote-props": ["error", "as-needed"],
21+
"no-console": "off",
22+
"process.env": false
23+
}
24+
}

‎LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ with two steps: (1) assert copyright on the software, and (2) offer
2929
you this License which gives you legal permission to copy, distribute
3030
and/or modify the software.
3131

32-
A secondary benefit of defending all users' freedom is that
32+
A secondary benefit of defending all users" freedom is that
3333
improvements made in alternate versions of the program, if they
3434
receive widespread use, become available for other developers to
3535
incorporate. Many developers of free software are heartened and
@@ -658,4 +658,4 @@ specific requirements.
658658
You should also get your employer (if you work as a programmer) or school,
659659
if any, to sign a "copyright disclaimer" for the program, if necessary.
660660
For more information on this, and how to apply and follow the GNU AGPL, see
661-
<http://www.gnu.org/licenses/>.
661+
<http://www.gnu.org/licenses/>.

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Then just require this module, it will start the server automatically.
3737

3838
For example, put in your index.js file:
3939
```
40-
const app = require('https-localhost')
41-
app.get('/', (req, res) => res.send('Hello World!'))
40+
const app = require("https-localhost")
41+
app.get("/", (req, res) => res.send("Hello World!"))
4242
```
4343

4444
#### Specify the port

‎index.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,63 @@
11
#!/usr/bin/env node
22

3-
const path = require('path')
4-
const fs = require('fs')
5-
const http = require('http')
6-
const https = require('spdy') // using HTTP/2: spdy will be deprecated soon, waiting for HTTP/2 on https module.
7-
const express = require('express')
8-
const compression = require('compression')
9-
10-
// SSL CERTIFICATE
3+
const path = require("path")
4+
const fs = require("fs")
5+
const http = require("http")
6+
// using HTTP/2: spdy will be deprecated soon,
7+
// waiting for HTTP/2 on https module.
8+
const https = require("spdy")
9+
const express = require("express")
10+
const compression = require("compression")
11+
12+
// SSL certificate
1113
const certOptions = {
12-
key: fs.readFileSync(path.resolve(__dirname + "/cert/server.key")),
13-
cert: fs.readFileSync(path.resolve(__dirname + "/cert/server.crt"))
14+
key: fs.readFileSync(path.resolve(__dirname, "cert/server.key")),
15+
cert: fs.readFileSync(path.resolve(__dirname, "cert/server.crt"))
1416
}
1517

1618
const port = process.env.PORT || 443
1719

18-
19-
// START THE APP
20-
2120
// run express
2221
const app = express()
2322
app.server = https.createServer(certOptions, app).listen(port)
2423

2524
// save sockets for fast close
2625
const sockets = []
2726
let nextSocketId = 0
28-
app.server.on('connection', socket => {
27+
app.server.on("connection", socket => {
2928
const socketId = nextSocketId++
3029
sockets[socketId] = socket
31-
socket.on('close', () => delete sockets[socketId])
30+
socket.on("close", () => delete sockets[socketId])
3231
})
3332

3433
// gzip compression and minify
3534
app.use(compression())
36-
app.set('json spaces', 0)
35+
app.set("json spaces", 0)
3736

3837
// redirect http to https
3938
if (port === 443 || process.env.HTTP_PORT) {
40-
app.http = http.createServer(function (req, res) {
41-
res.writeHead(301, {"Location": "https://" + req.headers['host'] + req.url})
39+
app.http = http.createServer((req, res) => {
40+
res.writeHead(301, { Location: "https://" + req.headers["host"] + req.url })
4241
res.end()
4342
}).listen(process.env.HTTP_PORT || 80)
4443

45-
app.http.on('connection', socket => {
44+
app.http.on("connection", socket => {
4645
const socketId = nextSocketId++
4746
sockets[socketId] = socket
48-
socket.on('close', () => delete sockets[socketId])
47+
socket.on("close", () => delete sockets[socketId])
4948
})
5049
}
5150

52-
// SERVE STATIC FILES, if launched as: 'node index.js <static-path>'
53-
if (require.main === module) { // called directly (not through require)
51+
// serve static files, if launched as: "node index.js <static-path>"
52+
if (require.main === module) {
5453
const staticPath = process.argv[2]
5554
app.use(express.static(staticPath || process.cwd()))
5655
}
5756

5857
// ready
5958
if (!process.env.TEST) console.info("Server running on port " + port + ".")
6059

61-
62-
// CLOSE THE APP
60+
// close the app
6361
app.close = (callback) => {
6462
const promises = [
6563
new Promise(resolve => app.http.close(resolve)),
@@ -68,12 +66,11 @@ app.close = (callback) => {
6866
// destroy all opens
6967
for (const socketId in sockets)
7068
sockets[socketId].destroy()
71-
7269
return Promise.all(promises).then(() => {
7370
if (!process.env.TEST) console.info("Server closed.")
7471
if (callback) callback()
7572
})
7673
}
7774

7875
// export as module
79-
module.exports = app
76+
module.exports = app

0 commit comments

Comments
 (0)
Please sign in to comment.