Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssl support #133

Merged
merged 1 commit into from
Oct 20, 2016
Merged
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
7 changes: 4 additions & 3 deletions src/browserify-plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ function LiveReactloadPlugin(b, opts = {}) {
host = null,
client = true,
dedupe = true,
debug = false
debug = false,
'ssl-cert': sslCert = null,
'ssl-key': sslKey = null,
} = opts

// server is alive as long as watchify is running
const server = opts.server !== false ? startServer({port: Number(port)}) : null
const server = opts.server !== false ? startServer({port: Number(port), sslCert, sslKey}) : null

const clientOpts = {
// assuming that livereload package is in global mdule directory (node_modules)
Expand Down Expand Up @@ -145,4 +147,3 @@ function LiveReactloadPlugin(b, opts = {}) {
}

module.exports = LiveReactloadPlugin

21 changes: 19 additions & 2 deletions src/browserify-plugin/server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import {Server} from "ws"
import {log} from "./console"
import https from 'https';
import {readFileSync} from 'fs';

function logError(error) {
if (error) {
log(error)
}
}

export function startServer({port}) {
const wss = new Server({port})
export function startServer({port, sslKey, sslCert}) {
if ((sslCert && !sslKey) || (!sslCert && sslKey)) {
throw new Error('You need both a certificate AND key in order to use SSL');
}

let wss;
if (sslCert && sslKey) {
const key = readFileSync(sslKey, 'utf8');
const cert = readFileSync(sslCert, 'utf8');
const credentials = {key, cert};
const server = https.createServer(credentials);
server.listen(port);
wss = new Server({server});
} else {
wss = new Server({port});
}


log("Reload server up and listening in port " + port + "...")

Expand Down