Skip to content
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
});
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {};
Expand Down
5 changes: 3 additions & 2 deletions lib/server-request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const http = require('http');
const https = require('https');
const REQUEST_TIMEOUT = 30000; // 30-seconds

/**
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions specs/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down