angular-mock-record
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -18,6 +18,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
MockUtilities.prototype.getMockRequest = function (endpoint, mockResponse, method) { | ||
var url = this.api_host + '/mock/' + endpoint + '?response=' + encodeURIComponent(JSON.stringify(mockResponse)); | ||
var url = this.api_host + '/mock/' + endpoint; | ||
var xmlHttp = new XMLHttpRequest(); | ||
if (!method) { | ||
xmlHttp.open('GET', url, false); | ||
xmlHttp.open('POST', url, false); | ||
} | ||
@@ -27,3 +27,4 @@ else { | ||
} | ||
xmlHttp.send(null); | ||
xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); | ||
xmlHttp.send(JSON.stringify(mockResponse)); | ||
return xmlHttp.responseText; | ||
@@ -30,0 +31,0 @@ }; |
{ | ||
"name": "angular-mock-record", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "An angular / protractor framework that mocks and records requests. Requests can be manually mocked or recorded like VCR.", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -8,3 +8,3 @@ class Mock { | ||
setRequestAsMocked(res, path, response) { | ||
this.mockedRequests[ path.replace('mock/', '') ] = JSON.parse(response); | ||
this.mockedRequests[ path.replace('mock/', '') ] = response; | ||
} | ||
@@ -11,0 +11,0 @@ |
@@ -25,3 +25,3 @@ const Http = require('./http.js'); | ||
this.mock.setRequestAsMocked(res, req.path, req.query.response); | ||
this.mock.setRequestAsMocked(res, req.path, req.body); | ||
res.status(200).send(true); | ||
@@ -28,0 +28,0 @@ |
const express = require('express'); | ||
const bodyParser = require("body-parser"); | ||
const RequestHandler = require('./request.handler.js'); | ||
@@ -10,2 +11,4 @@ let config = require('../../../mock.record.config.json'); | ||
this.app = express(); | ||
this.app.use( bodyParser.json() ); | ||
this.app.use( bodyParser.urlencoded({extended: true}) ); | ||
} | ||
@@ -15,3 +18,3 @@ | ||
this.app.listen(config.port || 3000, () => console.log('Mock API running on port ' + config.port + '..')); | ||
this.app.use((req, res) => { | ||
this.app.all('*', (req, res) => { | ||
req.url = this.rewritePathToMocks(req.url); | ||
@@ -18,0 +21,0 @@ this.requestHandler.handle(req, res); |
12269
375