From eaaebe78cd06160a6cb63b889bfe8bcda188a29a Mon Sep 17 00:00:00 2001 From: Qixiang Cheng Date: Mon, 11 Nov 2019 11:23:50 +0800 Subject: [PATCH 1/4] Dashboard: support HTTPS --- src/dashboard/server/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/dashboard/server/index.js b/src/dashboard/server/index.js index 7e7f8771a..cae32a24d 100644 --- a/src/dashboard/server/index.js +++ b/src/dashboard/server/index.js @@ -7,5 +7,24 @@ app.use(mount('/api', require('./api'))) app.use(require('./frontend')) if (require.main === module) { - app.listen(process.env.PORT || 3000, process.env.HOST) + const http = require('http') + const https = require('https') + const fs = require('fs') + + const { + HOST, + PORT = 3000, + TLS_KEY, + TLS_CERT + } = process.env + + const server = TLS_KEY && TLS_CERT + ? https.createServer({ + key: fs.readFileSync(TLS_KEY), + cert: fs.readFileSync(TLS_CERT) + }) + : http.createServer() + + server.on('request', app.callback()) + server.listen(PORT, HOST) } From 3acf62a716179efabdcdc227c1e7c11364a1368f Mon Sep 17 00:00:00 2001 From: Qixiang Cheng Date: Mon, 11 Nov 2019 13:14:40 +0800 Subject: [PATCH 2/4] Use SSL prefix instead of TLS --- src/dashboard/server/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dashboard/server/index.js b/src/dashboard/server/index.js index cae32a24d..3ae486cb9 100644 --- a/src/dashboard/server/index.js +++ b/src/dashboard/server/index.js @@ -14,14 +14,14 @@ if (require.main === module) { const { HOST, PORT = 3000, - TLS_KEY, - TLS_CERT + SSL_KEY, + SSL_CERT } = process.env - const server = TLS_KEY && TLS_CERT + const server = SSL_KEY && SSL_CERT ? https.createServer({ - key: fs.readFileSync(TLS_KEY), - cert: fs.readFileSync(TLS_CERT) + key: fs.readFileSync(SSL_KEY), + cert: fs.readFileSync(SSL_CERT) }) : http.createServer() From 5f199d6c48cf308f3990d53bda9045aa1af401ed Mon Sep 17 00:00:00 2001 From: Qixiang Cheng Date: Mon, 11 Nov 2019 13:33:18 +0800 Subject: [PATCH 3/4] Use HTTP/2 --- src/dashboard/server/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dashboard/server/index.js b/src/dashboard/server/index.js index 3ae486cb9..a797e7dac 100644 --- a/src/dashboard/server/index.js +++ b/src/dashboard/server/index.js @@ -8,7 +8,7 @@ app.use(require('./frontend')) if (require.main === module) { const http = require('http') - const https = require('https') + const http2 = require('http2') const fs = require('fs') const { @@ -19,7 +19,8 @@ if (require.main === module) { } = process.env const server = SSL_KEY && SSL_CERT - ? https.createServer({ + ? http2.createSecureServer({ + allowHTTP1: true, key: fs.readFileSync(SSL_KEY), cert: fs.readFileSync(SSL_CERT) }) From 1d352c800828a904c01b22ce68e3984808123f43 Mon Sep 17 00:00:00 2001 From: Qixiang Cheng Date: Mon, 11 Nov 2019 13:42:36 +0800 Subject: [PATCH 4/4] Document environment variables. --- src/dashboard/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dashboard/README.md b/src/dashboard/README.md index 5518166ae..049519d8a 100644 --- a/src/dashboard/README.md +++ b/src/dashboard/README.md @@ -8,7 +8,14 @@ DLTS dashboard is using [config](https://npmjs.com/package/config) to maintain c The configuration schema (with description) is maintained in [config.schema.json](./server/api/validator/config.schema.json). -## Local development +## Environment Variables + +- `HOST` the host of server listening, default `::` (IPv6) or `0.0.0.0` (IPv4). +- `PORT` the port of server listening, default `3000`. +- `SSL_KEY` the SSL/TLS private key file for HTTPS / HTTP2 support. +- `SSL_CERT` the SSL/TLS certificate file for HTTPS / HTTP2 support. + +## Local Development 1. Install [Node.js](https://nodejs.org/), version 10 is recommended. 2. Install [Yarn](https://yarnpkg.com/) for package maintaince.