Comparing version 0.0.2 to 0.0.4
exports.ServiceSync = require('./service.gen.sync'); | ||
exports.Api = require('./service.api'); | ||
exports.version = '0.0.4'; |
@@ -1,2 +0,1 @@ | ||
var config = require("config"); | ||
var path = require("path"); | ||
@@ -14,14 +13,8 @@ | ||
// load api from either given file or by default config/api.json | ||
var api = require(file || '../config/api.json'); | ||
var apiPath = path.resolve() + path.sep + 'config/api.json'; | ||
var api = require(file || apiPath); | ||
// append default config to api | ||
var target = api[name]; | ||
target.getPrefix = function() { | ||
return name; | ||
}; | ||
target.config = function() { | ||
return config; | ||
}; | ||
// if we want to create url on the fly | ||
if(urlCallback){ | ||
@@ -35,2 +28,2 @@ return urlCallback(target); | ||
exports.Api = internals.Api; | ||
exports.Api = module.exports = internals.Api; |
@@ -15,6 +15,8 @@ /*jshint loopfunc: true */ | ||
internals.Service = function(servJson) { | ||
if (servJson === null) { | ||
throw new Error("api.js needed"); | ||
internals.Service = function(servJson, host) { | ||
if (host === undefined) { | ||
throw new Error("Missing host when trying to create services..."); | ||
} | ||
this.proxy = undefined; | ||
this.host = host; | ||
return this.buildServices(servJson); | ||
@@ -25,27 +27,19 @@ }; | ||
internals.Service.prototype.setProxy = function(proxy) { | ||
this.proxy = proxy; | ||
} | ||
internals.Service.prototype.url = function(self) { | ||
// by default url will follow strict restful api protocol | ||
var config = this.config(); | ||
if (config) { | ||
// the schema passed in config will overwrite the schema defined in api.json | ||
if (config.server.host.indexOf("http://")===0 || config.server.host.indexOf("https://")===0) { | ||
return config.server.host + (self.path !== "" ? "/" + self.path : ""); | ||
} else { | ||
return self.schema + "://" + config.server.host + (self.path !== "" ? "/" + self.path : ""); | ||
//return self.schema + "://" + config.server.host + "/" + this.getPrefix() + (self.path != "" ? "/" + self.path : ""); | ||
} | ||
// the schema passed in config will overwrite the schema defined in api.json | ||
if (this.host.indexOf("http://")===0 || this.host.indexOf("https://")===0) { | ||
return this.host + (self.path !== "" ? "/" + self.path : ""); | ||
} else { | ||
throw new Error("config: function(){} need to be defined in api.js"); | ||
return self.schema + "://" + this.host + (self.path !== "" ? "/" + self.path : ""); | ||
} | ||
}; | ||
internals.Service.prototype.config = function() { | ||
return null; | ||
}; | ||
internals.Service.prototype.buildServices = function(services) { | ||
// in case overwritten by api.js | ||
this.url = services.url || this.url; | ||
this.config = services.config; | ||
this.getPrefix = services.getPrefix; | ||
@@ -152,3 +146,3 @@ for (var s in services) { | ||
}, | ||
proxy: this.config().server.proxy | ||
proxy: this.proxy | ||
}; | ||
@@ -155,0 +149,0 @@ |
{ | ||
"name": "bluecat", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"description": "REST API test framework in nodejs", | ||
@@ -5,0 +5,0 @@ "repository": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9791
258