diff --git a/index.js b/index.js index 23a25b8..fad81bb 100755 --- a/index.js +++ b/index.js @@ -560,7 +560,8 @@ class Hydra extends EventEmitter { resolve({ serviceName: this.serviceName, serviceIP: this.config.serviceIP, - servicePort: this.config.servicePort + servicePort: this.config.servicePort, + serviceProtocol: this.config.serviceProtocol }); } }); @@ -745,7 +746,8 @@ class Hydra extends EventEmitter { processID: process.pid, ip: this.config.serviceIP, port: this.config.servicePort, - hostName: this.hostName + hostName: this.hostName, + protocol: this.config.serviceProtocol }); if (entry && !this.redisdb.closing) { let cmd = (this.testMode) ? 'multi' : 'batch'; @@ -1264,6 +1266,7 @@ class Hydra extends EventEmitter { host: instance.ip, port: instance.port, path: parsedRoute.apiRoute, + protocol: `${(instance.protocol || 'http')}:`, method: parsedRoute.httpMethod.toUpperCase() }; let preHeaders = {}; diff --git a/lib/server-request.js b/lib/server-request.js index 8aeb5b7..3c56ef1 100644 --- a/lib/server-request.js +++ b/lib/server-request.js @@ -1,4 +1,5 @@ const http = require('http'); +const https = require('https'); const REQUEST_TIMEOUT = 30000; // 30-seconds /** @@ -28,8 +29,8 @@ class ServerRequest { } else { delete options.body; } - - let req = http.request(options, (res) => { + let requester = (options.protocol == 'http:') ? http : https; + let req = requester.request(options, (res) => { let response = []; res.on('data', (data) => { response.push(data); diff --git a/specs/index.test.js b/specs/index.test.js index 983950a..2f35e02 100644 --- a/specs/index.test.js +++ b/specs/index.test.js @@ -128,6 +128,30 @@ describe('Hydra Main', function() { }); }); + /** + * @description Hydra should load if serviceName and servicePort is provided + */ + it('should store as secured if protocol is set to https', (done) => { + hydra.init({ + hydra: { + 'serviceName': 'test-service', + 'servicePort': 3000, + 'serviceProtocol': 'https' + } + }, true) + .then(() => { + hydra.registerService().then((serviceInfo) => { + expect(serviceInfo).not.null; + expect(serviceInfo.serviceProtocol).to.equal('https'); + done(); + }); + }) + .catch((err) => { + expect(err).to.be.null; + done(); + }); + }); + /** * @description Hydra should load without a hydra.redis branch in configuration */