From e7b00ae239925b1c6364d80b86cc7001c316d991 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 2 Mar 2017 10:00:18 +0100 Subject: Use http2 on https connections --- bin/www | 13 +++++++++---- package.json | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/www b/bin/www index ef9dae5..8da634f 100755 --- a/bin/www +++ b/bin/www @@ -5,9 +5,14 @@ const app = require('../app') const http = require('http') const https = require('https') +const fileLocations = { + cert: '/etc/letsencrypt/live/rooster.hetmml.nl/fullchain.pem', + privkey: '/etc/letsencrypt/live/rooster.hetmml.nl/privkey.pem' +} + function setupHTTPS () { - const certificate = fs.readFileSync('/etc/letsencrypt/live/rooster.hetmml.nl/fullchain.pem', 'utf8') - const privateKey = fs.readFileSync('/etc/letsencrypt/live/rooster.hetmml.nl/privkey.pem', 'utf8') + const certificate = fs.readFileSync(fileLocations.cert, 'utf8') + const privateKey = fs.readFileSync(fileLocations.privkey, 'utf8') const credentials = { key: privateKey, cert: certificate } const httpsPort = normalizePort(process.env.PORT_HTTPS || '3001') @@ -88,7 +93,7 @@ function onListening (server) { let useHTTPS = true try { - fs.accessSync('/etc/letsencrypt/live/rooster.hetmml.nl/privkey.pem') + fs.accessSync(fileLocations.privkey) } catch (e) { useHTTPS = false } @@ -102,7 +107,7 @@ if (useHTTPS) { setupHTTP() } } else { - console.warn('NOT USING HTTPS! Could not read /etc/letsencrypt/live/rooster.hetmml.nl/privkey.pem') + console.warn(`NOT USING HTTPS! Could not read ${fileLocations.privkey}`) setupHTTP() } diff --git a/package.json b/package.json index 184d026..b1e56db 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "morgan": "~1.7.0", "request": "^2.74.0", "smoothscroll-polyfill": "^0.3.4", + "spdy": "^3.4.4", "then-yield": "0.0.1" }, "devDependencies": { -- cgit v1.1 From ec2cbd4954fb42f135f47d1e3db8d69301247080 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 2 Mar 2017 10:06:03 +0100 Subject: Actually use http2 on https connections --- bin/www | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/www b/bin/www index 8da634f..1c08756 100755 --- a/bin/www +++ b/bin/www @@ -3,7 +3,7 @@ const fs = require('fs') const app = require('../app') const http = require('http') -const https = require('https') +const https = require('spdy') const fileLocations = { cert: '/etc/letsencrypt/live/rooster.hetmml.nl/fullchain.pem', -- cgit v1.1 From d4ea3ff68f5b476aab009672968d3d348782a367 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 8 Mar 2017 11:07:42 +0100 Subject: Use 301 redirect instead of 302 --- bin/www | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/www b/bin/www index 1c08756..4c375d3 100755 --- a/bin/www +++ b/bin/www @@ -25,6 +25,11 @@ function setupHTTPS () { app.set('port', httpsPort) } +function redirectToHTTPS (req, res) { + res.writeHead(301, { 'Location': 'https://' + req.headers['host'] + req.url }) + res.end() +} + function setupHTTPSRedirect () { const httpPort = normalizePort(process.env.PORT || '3000') const httpServer = http.createServer(redirectToHTTPS) @@ -110,8 +115,3 @@ if (useHTTPS) { console.warn(`NOT USING HTTPS! Could not read ${fileLocations.privkey}`) setupHTTP() } - -function redirectToHTTPS (req, res) { - res.writeHead(302, { 'Location': 'https://' + req.headers['host'] + req.url }) - res.end() -} -- cgit v1.1