Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interfake

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interfake - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

48

lib/server.js

@@ -21,16 +21,18 @@ var express = require('express');

try {
this.createRoute(req.body);
createRoute(req.body);
res.send(200, { done : true });
} catch (e) {
this.debug('Error: ', e);
debug('Error: ', e);
res.send(400, e);
}
}.bind(this));
});
this.debug = function () {
function debug () {
if (o.debug) {
console.log.apply(console, arguments);
}
};
}
this.debug = debug;
function clearRouteForRequest(request) {

@@ -41,4 +43,4 @@ var i,j;

if (app.routes[request.method][i].path === request.url) {
this.debug('Clearing existing route at ' + request.method + ': ' + request.url + ' (1/2)');
app.routes[request.method].shift(i);
debug('Clearing existing route at ' + request.method + ': ' + request.url + ' (1/2)');
app.routes[request.method].splice(i);
break;

@@ -49,3 +51,3 @@ }

this.createRoute = function (data) {
function createRoute (data) {
var specifiedRequest, specifiedResponse, afterSpecifiedResponse;

@@ -57,7 +59,7 @@ if (!data.request || !data.request.method || !data.request.url || !data.response || !data.response.code) {

if (data.response.body) {
this.debug('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with a body of length ' + JSON.stringify(data.response.body).length);
debug('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with a body of length ' + JSON.stringify(data.response.body).length);
} else {
this.debug('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with no body');
debug('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with no body');
}
// this.debug('ROUTER obj: \n' + JSON.stringify(app._router.map));
// debug('ROUTER obj: \n' + JSON.stringify(app._router.map));

@@ -72,3 +74,3 @@ specifiedRequest = data.request;

var responseBody = specifiedResponse.body;
this.debug('Request to ' + specifiedRequest.url);
debug('Request to ' + specifiedRequest.url);

@@ -78,3 +80,3 @@ res.setHeader('Content-Type', 'application/json');

if (req.query.callback) {
this.debug('Request is asking for jsonp');
debug('Request is asking for jsonp');
if (typeof responseBody !== 'string') responseBody = JSON.stringify(responseBody);

@@ -88,13 +90,15 @@ responseBody = req.query.callback.trim() + '(' + responseBody + ');';

afterSpecifiedResponse.endpoints.forEach(function (endpoint) {
this.createRoute(endpoint);
}.bind(this));
createRoute(endpoint);
});
}
}.bind(this));
};
});
}
this.createRoute = createRoute;
this.listen = function (port) {
port = port || 3000;
server = app.listen(port, function () {
this.debug('Interfake is listening for requests on port ' + port);
}.bind(this));
debug('Interfake is listening for requests on port ' + port);
});
};

@@ -104,7 +108,7 @@

if (server) {
this.debug('Interfake is stopping');
debug('Interfake is stopping');
server.close(function () {
this.debug('Interfake has stopped');
debug('Interfake has stopped');
server = undefined;
}.bind(this));
});
}

@@ -111,0 +115,0 @@ };

{
"name": "interfake",
"preferGlobal": true,
"version": "1.0.1",
"version": "1.0.2",
"author": "Daniel Hough <daniel.hough@gmail.com>",

@@ -6,0 +6,0 @@ "description": "A simple way to create dummy APIs",

@@ -205,2 +205,3 @@ # Interfake: Mocked JSON APIs for any platform

* 1.0.2: Bugfix: Postresponse was removing the wrong old endpoint
* 1.0.0: Backwards-incompatible changes for JavaScript API, now creating an `Interfake` instance

@@ -207,0 +208,0 @@ * 0.2.0: Added JSONP support

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc