New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.0 to 1.0.1

16

index.js

@@ -5,10 +5,20 @@ #! /usr/bin/env node

var Interfake = require('./lib/server');
var interfake = new Interfake();
var packageInfo = require('./package.json');
program
.version('0.0.2')
.version(packageInfo.version)
.option('-f, --file [file]', 'Load an API from a JSON file [file]')
.option('-p --port [port]', 'Specify a port for Interfake to listen on', 3000)
.option('-d --debug', 'Debug mode, turns on console messages')
.parse(process.argv);
var file;
var opts = {
debug: false
};
if (program.debug) {
opts.debug = true;
}
var interfake = new Interfake(opts);
if (program.file) {

@@ -15,0 +25,0 @@ interfake.loadFile(program.file);

55

lib/server.js

@@ -8,7 +8,10 @@ var express = require('express');

function Interfake() {
function Interfake(o) {
o = o || { debug: false };
var app = express();
var server;
app.configure(function(){
app.use(express.bodyParser());
app.use(express.json());
app.use(express.urlencoded());
app.use(app.router);

@@ -22,7 +25,13 @@ });

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

@@ -33,3 +42,3 @@ var i,j;

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

@@ -41,3 +50,3 @@ break;

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

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

if (data.response.body) {
console.log('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with a body of length ' + JSON.stringify(data.response.body).length);
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);
} else {
console.log('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with no body');
this.debug('Setting up ' + data.request.method + ' ' + data.request.url + ' to return ' + data.response.code + ' with no body');
}
// console.log('ROUTER obj: \n' + JSON.stringify(app._router.map));
// this.debug('ROUTER obj: \n' + JSON.stringify(app._router.map));

@@ -64,3 +73,3 @@ specifiedRequest = data.request;

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

@@ -70,4 +79,5 @@ res.setHeader('Content-Type', 'application/json');

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

@@ -79,6 +89,6 @@

afterSpecifiedResponse.endpoints.forEach(function (endpoint) {
createRoute(endpoint);
});
this.createRoute(endpoint);
}.bind(this));
}
});
}.bind(this));
};

@@ -88,5 +98,16 @@

port = port || 3000;
app.listen(port);
console.log('Interfake is listening for requests on port ' + port);
server = app.listen(port, function () {
this.debug('Interfake is listening for requests on port ' + port);
}.bind(this));
};
this.stop = function () {
if (server) {
this.debug('Interfake is stopping');
server.close(function () {
this.debug('Interfake has stopped');
server = undefined;
}.bind(this));
}
};
}

@@ -93,0 +114,0 @@

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

@@ -15,3 +15,3 @@ "description": "A simple way to create dummy APIs",

"scripts": {
"test":"vows tests/test.js"
"test": "mocha tests/*.test.js --reporter spec"
},

@@ -38,3 +38,3 @@ "files": [

"dependencies": {
"express": "3.4.5",
"express": "^3.4.5",
"commander": "2.1.0"

@@ -51,4 +51,5 @@ },

"vows": "^0.7.0",
"request": "^2.34.0"
"request": "^2.34.0",
"q": "^1.0.1"
}
}

@@ -89,2 +89,10 @@ # Interfake: Mocked JSON APIs for any platform

### API
* `new Interfake(options)`: creates an Interfake object. Options are:
* `debug`: If `true`, outputs lots of annoying but helpful log messages. Default is `false`.
* `#createRoute(route)`: Takes a JSON object with `request`, `response` and optionally `afterResponse` properties
* `#listen(port)`: Takes a port and starts the server
* `#stop()`: Stops the server if it's been started
## Method 2: Command line

@@ -91,0 +99,0 @@

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