Repository: helix
Updated Branches:
  refs/heads/master dd05393cc -> fa587f0bf


[helix-front] Enable HTTPS server


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/7571d221
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/7571d221
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/7571d221

Branch: refs/heads/master
Commit: 7571d221bda79dd69c50a4a98418a604fb7dc42d
Parents: 201f25f
Author: Vivo Xu <v...@linkedin.com>
Authored: Thu Aug 24 15:40:03 2017 -0700
Committer: Junkai Xue <j...@linkedin.com>
Committed: Mon Nov 6 17:06:50 2017 -0800

----------------------------------------------------------------------
 helix-front/server/app.ts    | 36 ++++++++++++++++++++++++++++++++++--
 helix-front/server/config.ts |  8 ++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/7571d221/helix-front/server/app.ts
----------------------------------------------------------------------
diff --git a/helix-front/server/app.ts b/helix-front/server/app.ts
index 1d28783..222b04f 100644
--- a/helix-front/server/app.ts
+++ b/helix-front/server/app.ts
@@ -3,10 +3,16 @@ import * as dotenv from 'dotenv';
 import * as express from 'express';
 import * as morgan from 'morgan';
 import * as path from 'path';
+import * as fs from 'fs';
+import * as http from 'http';
+import * as https from 'https';
 
+import { SSL } from './config';
 import setRoutes from './routes';
 
 const app = express();
+const server = http.createServer(app);
+
 dotenv.load({ path: '.env' });
 app.set('port', (process.env.PORT || 3000));
 
@@ -22,8 +28,34 @@ app.get('/*', function(req, res) {
   res.sendFile(path.join(__dirname, '../public/index.html'));
 });
 
-app.listen(app.get('port'), () => {
-  console.log('App is listening on port ' + app.get('port'));
+server.listen(app.get('port'), () => {
+  console.log(`App is listening on port ${ app.get('port') } as HTTP`);
 });
 
+// setup SSL
+if (SSL.port > 0 && fs.existsSync(SSL.keyfile) && fs.existsSync(SSL.certfile)) 
{
+  let credentials: any = {
+    key: fs.readFileSync(SSL.keyfile, 'ascii'),
+    cert: fs.readFileSync(SSL.certfile, 'ascii'),
+    ca: []
+  };
+
+  if (SSL.passphrase) {
+    credentials.passphrase = SSL.passphrase;
+  }
+
+  if (SSL.cafiles) {
+    SSL.cafiles.forEach(cafile => {
+      if (fs.existsSync(cafile)) {
+        credentials.ca.push(fs.readFileSync(cafile, 'ascii'));
+      }
+    });
+  }
+
+  const httpsServer = https.createServer(credentials, app);
+  httpsServer.listen(SSL.port, () => {
+    console.log(`App is listening on port ${ SSL.port } as HTTPS`);
+  });
+}
+
 export { app };

http://git-wip-us.apache.org/repos/asf/helix/blob/7571d221/helix-front/server/config.ts
----------------------------------------------------------------------
diff --git a/helix-front/server/config.ts b/helix-front/server/config.ts
index 8780ad9..d38f848 100644
--- a/helix-front/server/config.ts
+++ b/helix-front/server/config.ts
@@ -3,3 +3,11 @@ export const HELIX_ENDPOINTS = {
     default: 'http://localhost:8100/admin/v2'
   }
 };
+
+export const SSL = {
+  port: 0,
+  keyfile: '',
+  certfile: '',
+  passphrase: '',
+  cafiles: []
+};

Reply via email to