mini-mock-api
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -7,3 +7,4 @@ var API = require('../lib/mini-mock-api'); | ||
mockPath: 'mock-files', | ||
idAttribute: '_id' | ||
idAttribute: '_id', | ||
cors: true | ||
}); | ||
@@ -10,0 +11,0 @@ |
@@ -19,2 +19,3 @@ 'use strict'; | ||
idAttribute: 'uuid', | ||
cors: false, | ||
sortParameter: 'sortOrder' | ||
@@ -24,2 +25,5 @@ }; | ||
this.app = express(); | ||
if(this.options.cors === true){ | ||
this.app.use(require('cors')()); | ||
} | ||
return this; | ||
@@ -46,3 +50,3 @@ }; | ||
console.log('Serving: ' + fileName); | ||
response.json(this.decorate(responseData)); | ||
response.json(this.decorate(responseData, request)); | ||
}.bind(this), | ||
@@ -69,3 +73,3 @@ | ||
console.log('Serving: ' + path.join(this.getFileName(splitted.path), splitted.id)); | ||
response.json(this.decorate(foundItem)); | ||
response.json(this.decorate(foundItem, request)); | ||
} else { | ||
@@ -72,0 +76,0 @@ response.sendStatus(404); |
{ | ||
"name": "mini-mock-api", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Lightweight node.js API mock server, route calls to static JSON files", | ||
@@ -28,2 +28,3 @@ "main": "lib/mini-mock-api.js", | ||
"dependencies": { | ||
"cors": "^2.7.1", | ||
"express": "^4.12.4", | ||
@@ -30,0 +31,0 @@ "lodash-node": "^3.9.3", |
@@ -68,2 +68,3 @@ # mini-mock-api | ||
idAttribute: 'uuid', //the id property to search for when requesting api/v1/cars/123 | ||
cors: false, //CORS headers for cross origin requests | ||
sortParameter: 'sortOrder' //the GET parameter for sort orders e.g. api/v1/cars?sortOrder=+name | ||
@@ -95,6 +96,6 @@ } | ||
All API responses can be decorated by defining a `decorate` function. In this example all returned collections are wrapped into `results` and a total count is added. | ||
All API responses can be decorated by defining a `decorate` function. The functions also gets passed the request object as the second parameter. In this example all returned collections are wrapped into `results` and a total count is added. | ||
``` | ||
myApi.decorate = function(data){ | ||
myApi.decorate = function(data, request){ | ||
if(data.length){ | ||
@@ -101,0 +102,0 @@ return { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11743
9
217
112
4
+ Addedcors@^2.7.1
+ Addedcors@2.8.5(transitive)
+ Addedobject-assign@4.1.1(transitive)