simple-json-replay-server
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "simple-json-replay-server", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple json replay server which can be used for standalone frontend web application (angular especially) when development. Simply put the url & parameters & response json data, then hit the url in browser or from your web application, whenever it matches the url and parameters, it will return the best match json data.", | ||
@@ -43,2 +43,3 @@ "main": "main.js", | ||
"chokidar": "^1.6.1", | ||
"cookie-parser": "^1.4.3", | ||
"express": "^4.15.0", | ||
@@ -45,0 +46,0 @@ "glob": "^7.1.1", |
@@ -141,2 +141,3 @@ # Simple JSON Replay Server ❤️ [![Build Status](https://travis-ci.org/realdah/simple-json-replay-server.svg?branch=master)](https://travis-ci.org/realdah/simple-json-replay-server) [![npm version](https://badge.fury.io/js/simple-json-replay-server.svg)](https://badge.fury.io/js/simple-json-replay-server) [![Node version](https://img.shields.io/node/v/simple-json-replay-server.svg?style=flat)](http://nodejs.org/download/) | ||
headers | key value pairs | Yes | default as undefined. Similiar to **query**, if you add any thing in here, it will filter out the data with headers having specific value. | ||
cookies | key value pairs | Yes | default as undefined. Similiar to **headers**, if you add any thing in here, it will filter out the data with cookies having specific value. **(Do not support secured cookies for now)** | ||
@@ -278,4 +279,4 @@ ### ✦ Response | ||
0.1.2 | support 302 forwarding with a location (relative path or absolute path) | ||
0.1.3 | support support cookie matching | ||
--- | ||
@@ -282,0 +283,0 @@ |
@@ -11,3 +11,7 @@ var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
var cookieParser = require('cookie-parser') | ||
var app = express(); | ||
app.use(cookieParser()) | ||
@@ -14,0 +18,0 @@ //beautify the JSON output from mock server, this will give a lot of convenient during development. |
var _ = require('underscore'); | ||
var util = require('./util'); | ||
var NOT_MATCH = -999999; | ||
function matchRequests(request, requestMappings) { | ||
var path = request.path.toLowerCase(); | ||
var query = request.query; | ||
var cookies = request.cookies; | ||
var body = request.body; | ||
@@ -46,4 +45,10 @@ var headers = request.headers; | ||
var score = queryScore + bodyScore + headerScore; | ||
if(headerScore < 0) { | ||
return; | ||
} | ||
var cookieScore = util.partialContains(cookies, mockDataConfig.request.cookies); | ||
var score = queryScore + bodyScore + headerScore + cookieScore; | ||
if(score >= bestScore) { | ||
@@ -50,0 +55,0 @@ bestScore = score; |
63209
27
982
286
7
+ Addedcookie-parser@^1.4.3
+ Addedcookie@0.7.2(transitive)
+ Addedcookie-parser@1.4.7(transitive)