gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

server shutdown when request data is invalid #64

Closed pauldeng100 closed 8 years ago

pauldeng100 commented 8 years ago

Please see my log output. if the request data is invalid, the server will be shutdown. I am working on window, i am not sure if linux have the sample probleam

C:\Users\pauldeng>apimocker Loading config file: C:\Users\pauldeng\AppData\Roaming\npm\node_modules\apimocker\config.json Set route: GET first : king.json 20 ms Set route: POST first : ace.json 20 ms Set route: DELETE second : 50 ms Set route: POST second : king.json 50 ms Set route: POST nested/ace : ace.json 50 ms with switch on param: customerId Set route: GET nested/ace : ace.json 50 ms with switch on param: customerId Set route: POST nested/ace2 : ace.json 50 ms with switch on param: [ 'customerId', 'multitest' ] Set route: GET nested/ace2 : ace.json 50 ms with switch on param: [ 'customerId', 'multitest' ] Set route: ALL var/:id/:color : xml/queen.xml 50 ms with switch on param: [ 'id', 'color' ] Set route: POST login : sorry.json 50 ms with switch on param: [ 'userId', 'password' ] Set route: GET template/:name/:number : templateSample.json 50 ms Set route: GET templateSwitchGetParams : templateSwitchSample.json 50 ms Set route: POST templateSwitchPostJsonPath : templateSwitchSample.json 50 ms Mock server listening on port 7878 Returning mock: GET first : king.json templateSwitch[appID] value NOT FOUND templateSwitch[appName] value NOT FOUND templateSwitch[userName] value NOT FOUND templateSwitch[userAge] value NOT FOUND Returning mock: GET templateSwitchGetParams : templateSwitchSample.json C:\Users\pauldeng\AppData\Roaming\npm\node_modules\apimocker\lib\apimocker.js:190 key = switches[s].key; ^

TypeError: Cannot read property 'key' of undefined at C:\Users\pauldeng\AppData\Roaming\npm\node_modules\apimocker\lib\apimocker.js:190:24 at Array.forEach (native) at Object.apiMocker.fillTemplateSwitch (C:\Users\pauldeng\AppData\Roaming\npm\node_modules\apimocker\lib\apimocker.js:186:12) at C:\Users\pauldeng\AppData\Roaming\npm\node_modules\apimocker\lib\apimocker.js:268:28 at FSReqWrap.readFileAfterClose as oncomplete C:\Users\pauldeng>

pauldeng100 commented 8 years ago

I found another one http-mock-server in https://www.npmjs.com/package/http-mock-server. it seems this version didn't have this issue.

ferrerod commented 8 years ago

Paul please provide an example config file with the templateSwitch and the mock file and an example request that causes this to fail.. with that I can see what might be going on in templateSwitch

pauldeng100 commented 8 years ago

config.zip Hi ferrerod, please find attahced config.zip.

1) For templateSwitchGetParams, if I don't pass any parameter in query string, the whole service will shutdown. 2) I'am very interested in apimocker. can you advise how I can make the configration for below cases for rest/GetProductOrder endpoint wihch I haved placed in config.json? 2a) if $.Body.CustomerOrder.shoppingCartID0000 is null or empty string, set mockFile to 0000.json. 2b) if $.Body.CustomerOrder.shoppingCartID>1000 then set mockFile to 1000plus.json 2c) or even more complex, if $.Body.CustomerOrder.shoppingCartID!=null && $.Body.CustomerOrder.customerAccountId!=null , then set mockFile to good.json.

Thanks in advance.$$$$$$$$$$$$$$$$$

gstroup commented 8 years ago

@ferrerod any thoughts on this, before I dig in to it? seems like a bug we should fix...

ferrerod commented 8 years ago

Sorry been 100% on another project. If it's urgent go ahead. I don't have an estimate when I can have a look.

gstroup commented 8 years ago

Fixed in v0.4.16.