Skip to content

Commit

Permalink
Merge e73c141 into a7cc802
Browse files Browse the repository at this point in the history
  • Loading branch information
daquinoaldo committed Sep 2, 2019
2 parents a7cc802 + e73c141 commit 1c8083b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ npm i -s https-localhost
```
Then put in your `index.js` file:
```javascript
const httpsLocalhost = require("https-localhost")
const app = httpsLocalhost()
const app = require("https-localhost")()
// app is an express app, do what you usually do with express
app.listen(port)
```
Expand All @@ -76,6 +75,14 @@ app.listen(port)
**Tip:** consider installing it as a dev dependency: this is not a production tool!
`npm i --save-dev https-localhost`

#### Use with a web framework different from Express.js
```javascript
const httpsLocalhost = require("https-localhost")()
// const app = ...
// const port = 443
const certs = await httpsLocalhost.getCerts()
const server = https.createServer(certs, app).listen(port)
```

## Production
This tool has a production version that activates **HTTP/2**, **compression** and **minify**.
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const createServer = () => {
// create a server with express
const app = express()

// add getCerts to app
app.getCerts = getCerts

// override the default express listen method to use our server
app.listen = async function(port = process.env.PORT ||
/* istanbul ignore next: cannot be tested on Travis */ 443) {
Expand Down
48 changes: 28 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "https-localhost",
"version": "4.2.1",
"version": "4.3.0",
"description": "HTTPS server running on localhost",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -52,7 +52,7 @@
},
"devDependencies": {
"coveralls": "^3.0.6",
"eslint": "^6.2.2",
"eslint": "^6.3.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^9.2.0",
Expand All @@ -61,6 +61,6 @@
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"pkg": "^4.4.0",
"sinon": "^7.4.1"
"sinon": "^7.4.2"
}
}
15 changes: 14 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ describe("Testing certs", function() {
done()
})()
})

it("provides the certificate", function(done) {
// inner async function
(async() => {
const appCerts = await app.getCerts()
const realCerts = await certs.getCerts()
assert.deepStrictEqual(appCerts, realCerts)
done()
})()
})
})

// TESTS MODULE
Expand Down Expand Up @@ -283,7 +293,10 @@ describe("Testing redirect", () => {
})

// OTHER TESTS
describe("Testing additional features", () => {
describe("Testing additional features", function() {
// timeout 10 secs, since sometimes 3 secs are not sufficient
this.timeout(10000)

it("is ready for production", function(done) {
(async() => {
// set NODE_ENV to production
Expand Down

0 comments on commit 1c8083b

Please sign in to comment.