From 572ed5b823f234ec00b7731dbe9ccb20f923f737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Sch=C3=B6ning?= Date: Tue, 23 Feb 2016 11:49:28 +0100 Subject: [PATCH] Implement HTTP/2 support when the http2 package is installed and HTTPS is enabled --- package.json | 3 +++ src/index.coffee | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c742c40..41a5e92 100644 --- a/package.json +++ b/package.json @@ -55,5 +55,8 @@ "gulp-stylus": "^2.1.1", "mocha": "^2.3.4", "supertest": "^1.1.0" + }, + "optionalDependencies": { + "http2": "^3.3.2" } } diff --git a/src/index.coffee b/src/index.coffee index 54ac4b2..06a1bd1 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -11,6 +11,10 @@ opt = {} server = undefined lr = undefined +http2 = undefined +try + http2 = require('http2') + class ConnectApp constructor: (options) -> opt = options @@ -29,7 +33,7 @@ class ConnectApp else app.use middleware if opt.https? - server = https.createServer + server = (http2 || https).createServer key: opt.https.key || fs.readFileSync __dirname + '/certs/server.key' cert: opt.https.cert || fs.readFileSync __dirname + '/certs/server.crt' ca: opt.https.ca || fs.readFileSync __dirname + '/certs/ca.crt'