From 2a8c959d095a58ee5bd65831ec1ee0ab81703ca8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 25 Nov 2017 08:11:58 +0900 Subject: [PATCH] :v: --- docs/config.md | 11 ++++------- src/config.ts | 7 +------ src/server.ts | 18 +++++++++++------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/docs/config.md b/docs/config.md index 0e23e09ae8..653fff1a7f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -16,14 +16,11 @@ secondary_url: # 待受ポート port: -# TLSの設定 +# TLSの設定(利用しない場合は省略可能) https: - # TLSを有効にするか否か - enable: false - - key: null - cert: null - ca: null + # 証明書のパス... + key: + cert: # MongoDBの設定 mongodb: diff --git a/src/config.ts b/src/config.ts index 7237b666f2..3ff8007586 100644 --- a/src/config.ts +++ b/src/config.ts @@ -38,12 +38,7 @@ type Source = { url: string; secondary_url: string; port: number; - https: { - enable: boolean; - key: string; - cert: string; - ca: string; - }; + https?: { [x: string]: string }; mongodb: { host: string; port: number; diff --git a/src/server.ts b/src/server.ts index 9cf44eb0d0..a2165d672b 100644 --- a/src/server.ts +++ b/src/server.ts @@ -61,13 +61,17 @@ app.use(require('./web/server')); /** * Create server */ -const server = config.https.enable ? - https.createServer({ - key: fs.readFileSync(config.https.key), - cert: fs.readFileSync(config.https.cert), - ca: fs.readFileSync(config.https.ca) - }, app) : - http.createServer(app); +const server = (() => { + if (config.https) { + const certs = {}; + Object.keys(config.https).forEach(k => { + certs[k] = fs.readFileSync(config.https[k]); + }); + return https.createServer(certs, app); + } else { + return http.createServer(app); + } +})(); /** * Steaming