Skip to content

Commit

Permalink
Merge branch 'f/LIB-572-option-to-override-protocol' into 'master'
Browse files Browse the repository at this point in the history
Merge of f/LIB-572-option-to-override-protocol to master

Closes LIB-572

See merge request PAS/bridge/bridge-lib!2
  • Loading branch information
p-muessig committed Oct 30, 2023
2 parents ce945d3 + 8404e4b commit 404f3d5
Show file tree
Hide file tree
Showing 6 changed files with 2,746 additions and 141 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ npm install e2e-bridge-lib

``` javascript
var E2EBridge = require('e2e-bridge-lib');
var bridgeInstance = new E2EBridge('localhost', 8080, 'admin', 'admin');
var bridgeInstance = new E2EBridge('https', localhost', 8080, 'admin', 'admin');
bridgeInstance.startXUMLService('PurchaseOrderExample', function(error){
if(error) {
Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ const defaultStopOptions = Object.freeze({

/**
* Bridge object
* @param {string} protocol
* @param {string} host
* @param {number} port
* @param {?string} user
* @param {?string} password
* @constructor
*/
function Bridge(host, port, user, password) {
function Bridge(protocol, host, port, user, password) {
if (protocol && !(protocol === 'http' || protocol === 'https')) {
throw new Error(`Unsupported protocol '${protocol}'. Allowed protocols: 'http' or 'https'`);
}
this._protocol = protocol || 'https';
this._host = host || 'localhost';
this._port = port || 8080;
this._user = user;
Expand Down Expand Up @@ -239,7 +244,7 @@ Bridge.prototype._composeRequestObject = function(method, endpoint, content, get
method = method.toUpperCase();

let ret = {
"url": 'https://' + self._host + ':' + self._port + BRIDGE_REST_API_BASE + endpoint,
"url": `${self._protocol}://${self._host}:${self._port}${BRIDGE_REST_API_BASE}${endpoint}`,
"qs": getParams,
"method": method,
"strictSSL": false, //because bridge uses self-signed certificate
Expand Down Expand Up @@ -1410,14 +1415,15 @@ Bridge.prototype.removeUser = function(id, callback) {

/**
* Factory function for the Bridge instances
* @param {string} protocol
* @param {string} host
* @param {number} port
* @param {?string} user
* @param {?string} password
* @constructs Bridge
*/
function createInstance(host, port, user, password) {
return new Bridge(host, port, user, password);
function createInstance(protocol, host, port, user, password) {
return new Bridge(protocol, host, port, user, password);
}

/** Exports **/
Expand Down
Loading

0 comments on commit 404f3d5

Please sign in to comment.