Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Add option for using TLS #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ Everything else: [https://trac.ffmpeg.org/wiki/CompilationGuide](https://trac.ff
cp local.json-dist local.json
npm start

## Using TLS

You can configure the server to use TLS by including a `tls` option in `local.json`. The `tls` option eventually gets passed as the "options" object to [`tls.createServer`](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener).

Within the `tls` option, you can either specify `key` and `cert` using the PEM-formatted data of the private key and the certificate, respectively, or `keyFile` and `certFile`, in which case the private key and the certificate will be read from files.

Sample config file:

```
{
"domain": "localhost",
"port": 3000,
"wsServer": "ws://localhost:3000",
"tls": {"keyFile": "key.pem", "certFile": "cert.pem"}
}
```

Using TLS can be desirable, since recent versions of Chrome don't allow accessing the camera unless the web site is either accessed as `localhost` or uses TLS.

## Accessing the API

This is using the latest version of [socket.io](http://socket.io) and will not work with the old version from the previous meatspace API.
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ var Hapi = require('hapi');
var nconf = require('nconf');
var SocketIO = require('socket.io');
var crypto = require('crypto');
var fs = require('fs');

var services = require('./lib/services');

nconf.argv().env().file({ file: 'local.json' });

var users = 0;

var server = Hapi.createServer(nconf.get('domain'), nconf.get('port'));
var tlsOptions = nconf.get('tls');
if (tlsOptions) {
if ('keyFile' in tlsOptions) {
tlsOptions['key'] = fs.readFileSync(tlsOptions['keyFile']);
}
if ('certFile' in tlsOptions) {
tlsOptions['cert'] = fs.readFileSync(tlsOptions['certFile']);
}
}
var hapiOptions = {tls: tlsOptions};
var server = Hapi.createServer(nconf.get('domain'), nconf.get('port'), hapiOptions);
server.views({
engines: {
jade: require('jade')
Expand Down