Skip to content

Commit d570d16

Browse files
dloedaNEXT-diego-hernando
authored andcommitted
✨ feat(server): Allow to read body from JS mock
1 parent b8efbd0 commit d570d16

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This wil return JSON response at it's defined in the JSON file.
2424
```
2525
### Execute JS file
2626
```javascript
27-
/*globals req, params, query, mock*/
27+
/*globals req, params, body, query, mock*/
2828
mock = {
2929
'id': Math.floor(Math.random()*1000),
3030
'userId': params.userId

libs/finder.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function openMock(config, req) {
101101
fileInfo.context = {
102102
req: req,
103103
params: fileInfo.params,
104+
body: req.body,
104105
query: fileInfo.query,
105106
mock: false
106107
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mock-js-server",
3-
"version": "0.0.11",
3+
"version": "0.1.0",
44
"description": "Mock server for API",
55
"scripts": {
66
"start": "node server.js -v -p 3000"

server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var utils = require('./libs/utils');
88
var logger = require('./libs/logger');
99
var app = express();
1010

11+
app.use(express.json())
12+
1113
app.use((req, _, next) =>
1214
setTimeout(() => {
1315
next()

0 commit comments

Comments
 (0)