Socket
Socket
Sign inDemoInstall

caddis

Package Overview
Dependencies
189
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.5 to 0.3.6

features/response-delay.feature

34

lib/caddis/server.js

@@ -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 @@ }

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc