Skip to content

Commit

Permalink
Work-in-progress HTTP2 support via "spdy" module
Browse files Browse the repository at this point in the history
This works, but it looks like the "spdy" module (which, despite its name, also supports http2)
is not compatible with newer nodejs versions and should be avoided:
spdy-http2/node-spdy#333
webpack/webpack-dev-server#1451

Should eventually use nodejs's native http2 module, but it is currently incompatible with express:
expressjs/express#3388

Committing the changes to a branch and setting aside for now.
  • Loading branch information
shesek committed Sep 1, 2018
1 parent f598671 commit d43e4f4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
84 changes: 79 additions & 5 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"morgan": "^1.9.0",
"nanoid": "^1.1.0",
"qrcode": "^1.2.2",
"spdy": "^3.4.7",
"superagent": "^3.8.3"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const args = require('meow')(`
-q, --print-qr print QR code with the server URL [default: false]
-Q, --pairing-qr print QR code with embedded access key [default: false]
--no-webui run API server without serving client assets [default: false]
--no-http2 disable HTTP/2.0 support [default: enabled when TLS is]
-C, --config-path <path> path to config file [default: ~/.spark-wallet/config]
-V, --verbose display debugging information [default: false]
Expand Down
10 changes: 8 additions & 2 deletions src/transport/tls.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import forge from 'node-forge'
import path from 'path'
import https from 'https'
import http from 'http'
import isIp from 'is-ip'
import fs from 'fs'
import mkdirp from 'mkdirp'

const defaultDir = path.join(require('os').homedir(), '.spark-wallet', 'tls')

// the "spdy" module in fact supports http/2.0 despite its confusing name.
// we're using it (with spdy support turned off) because the native "http2" module
// is not currently compatible with Express. https://github.com/expressjs/express/issues/3388

const https = process.env.NO_HTTP2 ? require('https') : require('spdy')
, srvOpt = process.env.NO_HTTP2 ? {} : { protocols: [ 'h2', 'http/1.1', 'http/1.0' ] }

module.exports = (app, name=app.settings.host, dir=defaultDir, leEmail) => {
const tlsOpt = leEmail ? letsencrypt(name, dir, leEmail) : selfsigned(name, dir)
, server = https.createServer(tlsOpt, app)
, server = https.createServer( { ...tlsOpt, ...srvOpt }, app)

tlsOpt.cert && app.get('/cert.pem', (req, res) => res.type('pem').send(tlsOpt.cert))
// @TODO allow downloading letsencrypt's cert
Expand Down

0 comments on commit d43e4f4

Please sign in to comment.