Skip to content

Commit

Permalink
Merge pull request #128 from BryceCicada/master
Browse files Browse the repository at this point in the history
Allow SSL/TLS connections
  • Loading branch information
theninj4 committed May 24, 2016
2 parents 9685820 + 9cec06c commit 33919a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
34 changes: 34 additions & 0 deletions documentation/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ jsonApi.setConfig({
});
```

#### Configuring HTTPS

To run over HTTPS, set the protocol to _https_ and configure the appropriate TLS settings

For example:

```javascript
var fs = require("fs");
jsonApi.setConfig({
protocol: "https",
port: 16006,
tls: {
cert: fs.readFileSync('server.crt'),
key: fs.readFileSync('server.key')
passphrase: 'pass'
}
});
```
or

```javascript
var fs = require("fs");
jsonApi.setConfig({
protocol: "https",
port: 16006,
tls: {
pfx: fs.readFileSync('server.pfx'),
passphrase: 'pass'
}
});
```

For a full set of tls options, see https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener

#### Error Handling

```javascript
Expand Down
8 changes: 7 additions & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ app.route("*").all(function(req, res, next) {
});

router.listen = function(port) {

if (!server) {
server = app.listen(port);
if (jsonApi._apiConfig.protocol === "https") {
server = require("https").createServer(jsonApi._apiConfig.tls || {}, app);
} else {
server = require("http").createServer(app);
}
server.listen(port);
}
};

Expand Down

0 comments on commit 33919a5

Please sign in to comment.