json-server
Advanced tools
Comparing version
@@ -7,4 +7,6 @@ "use strict"; | ||
const request = require('request'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
const low = require('lowdb'); | ||
@@ -48,10 +50,16 @@ | ||
} else if (is.URL(source)) { | ||
// Load remote data | ||
const opts = { | ||
url: source, | ||
json: true | ||
}; | ||
request(opts, (err, response) => { | ||
if (err) return reject(err); | ||
resolve(low(new Memory()).setState(response.body)); | ||
// Normalize the source into a URL object. | ||
const sourceUrl = new URL(source); // Pick the client based on the protocol scheme | ||
const client = sourceUrl.protocol === 'https:' ? https : http; | ||
client.get(sourceUrl, res => { | ||
let dbData = ''; | ||
res.on('data', data => { | ||
dbData += data; | ||
}); | ||
res.on('end', () => { | ||
resolve(low(new Memory()).setState(JSON.parse(dbData))); | ||
}); | ||
}).on('error', error => { | ||
return reject(error); | ||
}); | ||
@@ -58,0 +66,0 @@ } else if (is.JS(source)) { |
{ | ||
"name": "json-server", | ||
"version": "0.16.1", | ||
"version": "0.16.2", | ||
"description": "Get a full fake REST API with zero coding in less than 30 seconds", | ||
@@ -35,3 +35,2 @@ "main": "./lib/server/index.js", | ||
"pluralize": "^8.0.0", | ||
"request": "^2.88.2", | ||
"server-destroy": "^1.0.1", | ||
@@ -38,0 +37,0 @@ "update-notifier": "^4.0.0", |
@@ -126,3 +126,3 @@ # JSON Server [](https://travis-ci.org/typicode/json-server) [](http://badge.fury.io/js/json-server) | ||
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken. | ||
- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data. | ||
- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it will return a 2XX status code, but without changes being made to the data. | ||
@@ -595,3 +595,2 @@ ## Routes | ||
* [Node Module Of The Week - json-server](http://nmotw.in/json-server/) | ||
* [Mock up your REST API with JSON Server](http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/) | ||
* [ng-admin: Add an AngularJS admin GUI to any RESTful API](http://marmelab.com/blog/2014/09/15/easy-backend-for-your-restful-api.html) | ||
@@ -598,0 +597,0 @@ * [Fast prototyping using Restangular and Json-server](https://glebbahmutov.com/blog/fast-prototyping-restangular-and-json-server/) |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
20
-4.76%66567
-3.68%37
-5.13%1122
-9.52%613
-0.16%2
Infinity%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed