Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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',
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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: {
Expand All @@ -201,4 +212,4 @@ Odoo.prototype._request = function (path, params, cb) {
});
};

module.exports = Odoo;
module.exports = Odoo;