Skip to content

Commit 0524415

Browse files
authored
Get certs (#24)
Exposes getCerts to use them with a web framework different from Express.js. v4.3.0. Resolve #20. Update dependencies.
1 parent a7cc802 commit 0524415

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ npm i -s https-localhost
6464
```
6565
Then put in your `index.js` file:
6666
```javascript
67-
const httpsLocalhost = require("https-localhost")
68-
const app = httpsLocalhost()
67+
const app = require("https-localhost")()
6968
// app is an express app, do what you usually do with express
7069
app.listen(port)
7170
```
@@ -76,6 +75,14 @@ app.listen(port)
7675
**Tip:** consider installing it as a dev dependency: this is not a production tool!
7776
`npm i --save-dev https-localhost`
7877

78+
#### Use with a web framework different from Express.js
79+
```javascript
80+
const httpsLocalhost = require("https-localhost")()
81+
// const app = ...
82+
// const port = 443
83+
const certs = await httpsLocalhost.getCerts()
84+
const server = https.createServer(certs, app).listen(port)
85+
```
7986

8087
## Production
8188
This tool has a production version that activates **HTTP/2**, **compression** and **minify**.

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const createServer = () => {
1616
// create a server with express
1717
const app = express()
1818

19+
// add getCerts to app
20+
app.getCerts = getCerts
21+
1922
// override the default express listen method to use our server
2023
app.listen = async function(port = process.env.PORT ||
2124
/* istanbul ignore next: cannot be tested on Travis */ 443) {

package-lock.json

Lines changed: 28 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "https-localhost",
3-
"version": "4.2.1",
3+
"version": "4.3.0",
44
"description": "HTTPS server running on localhost",
55
"main": "index.js",
66
"scripts": {
@@ -52,7 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"coveralls": "^3.0.6",
55-
"eslint": "^6.2.2",
55+
"eslint": "^6.3.0",
5656
"eslint-config-standard": "^14.1.0",
5757
"eslint-plugin-import": "^2.18.2",
5858
"eslint-plugin-node": "^9.2.0",
@@ -61,6 +61,6 @@
6161
"mocha": "^6.2.0",
6262
"nyc": "^14.1.1",
6363
"pkg": "^4.4.0",
64-
"sinon": "^7.4.1"
64+
"sinon": "^7.4.2"
6565
}
6666
}

test/test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ describe("Testing certs", function() {
116116
done()
117117
})()
118118
})
119+
120+
it("provides the certificate", function(done) {
121+
// inner async function
122+
(async() => {
123+
const appCerts = await app.getCerts()
124+
const realCerts = await certs.getCerts()
125+
assert.deepStrictEqual(appCerts, realCerts)
126+
done()
127+
})()
128+
})
119129
})
120130

121131
// TESTS MODULE
@@ -283,7 +293,10 @@ describe("Testing redirect", () => {
283293
})
284294

285295
// OTHER TESTS
286-
describe("Testing additional features", () => {
296+
describe("Testing additional features", function() {
297+
// timeout 10 secs, since sometimes 3 secs are not sufficient
298+
this.timeout(10000)
299+
287300
it("is ready for production", function(done) {
288301
(async() => {
289302
// set NODE_ENV to production

0 commit comments

Comments
 (0)