diff --git a/lib/index.js b/lib/index.js index 8e7a74c..3968ebe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,11 +5,14 @@ var Odoo = function (config) { this.host = config.host; this.port = config.port || 80; + this.secure = this.port == 443; this.database = config.database; this.username = config.username; this.password = config.password; }; + + // Connect Odoo.prototype.connect = function(cb){ @@ -20,7 +23,7 @@ Odoo.prototype.connect = function(cb){ }; var json = JSON.stringify({ params: params }); - var url = 'http://' + this.host + ':' + this.port + '/web/session/authenticate'; + var url = this.get_base_url() + '/web/session/authenticate'; var options = { method: 'POST', @@ -53,6 +56,14 @@ Odoo.prototype.connect = function(cb){ }; +Odoo.prototype.get_base_url = function(){ + var regex = "http[s]?:\/\/.*$"; + var url = '' + if(!this.host.match(regex)) + url = this.secure ? 'https://' : 'http://'; + return url + this.host + ':' + this.port; +} + // Search records Odoo.prototype.search = function (model, params, callback) { // assert(params.ids, "Must provide a list of IDs."); @@ -177,7 +188,7 @@ Odoo.prototype.rpc_call = function (endpoint, params, callback) { Odoo.prototype._request = function (path, params, cb) { params = params || {}; - var url = 'http://' + this.host + ':' + this.port + (path || '/') + ''; + var url = this.get_base_url() + (path || '/') + ''; var options = { method: 'POST', headers: { @@ -201,4 +212,4 @@ Odoo.prototype._request = function (path, params, cb) { }); }; -module.exports = Odoo; +module.exports = Odoo; \ No newline at end of file