caddis
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -12,2 +12,12 @@ 'use strict'; | ||
var validateStatusCode = function(value) { | ||
// Enhancement: Validate as proper HTTP status code. | ||
return isValidInt(value) ? parseInt(value, 10) : Number.NaN; | ||
}; | ||
var validateDelay = function(value) { | ||
// Enhancement: Validate as proper timespan. | ||
return isValidInt(value) ? parseInt(value, 10) : Number.NaN; | ||
}; | ||
var convertToJSONHash = function(objectOrString) { | ||
@@ -43,11 +53,29 @@ return typeof objectOrString === 'string' ? JSON.parse(objectOrString) : objectOrString; | ||
var delay = validateDelay(config.delay); | ||
var statusCode = validateStatusCode(config.status); | ||
var jsonResponse = convertToJSONHash(config.response); | ||
app[config.method.toLowerCase()](config.uri, function(request, response) { | ||
if(config.status && isValidInt(config.status)) { | ||
response.status(parseInt(config.status, 10)).json(jsonResponse); | ||
var timeout; | ||
var respond = function() { | ||
if(!isNaN(statusCode)) { | ||
response.status(statusCode).json(jsonResponse); | ||
} | ||
else { | ||
response.json(jsonResponse); | ||
} | ||
}; | ||
if(!isNaN(delay)) { | ||
timeout = setTimeout(function() { | ||
clearTimeout(timeout); | ||
respond(); | ||
}, delay); | ||
} | ||
else { | ||
response.json(jsonResponse); | ||
respond(); | ||
} | ||
}); | ||
res.json({result:true}); | ||
@@ -54,0 +82,0 @@ } |
{ | ||
"name": "caddis", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -89,6 +89,7 @@ Caddis | ||
* method: The REST method | ||
* uri: The endpoint of the service to hit (requires prepended '/') | ||
* response: The JSON object to return on request | ||
* statusCode: [Optional] Status code to return. Defaults to 200 | ||
* __method__: The REST method | ||
* __uri__: The endpoint of the service to hit (requires prepended '/') | ||
* __response__: The JSON object to return on request | ||
* __statusCode__: [Optional] Status code to return. Defaults to 200 | ||
* __delay__: [Optional] Time delay, in milliseconds, to delay response. Defaults to NaN | ||
@@ -95,0 +96,0 @@ Tests |
23931
33
408
126