This is a very simple mock server. Simplify returning static data on http requests.
It supports returning different static files requested with a specific url, method or query-parameters.
Return mock data specified by:
- url (e.g.:
/customer
) - method (e.g.:
GET
,POST
) - query-parameter (e.g.:
?page=2&sort=name,desc
)
- Navigate into your MagicMirror's modules folder and execute
git clone https://github.com/JanLoebel/simplest-mock-server.git
- Execute
cd simplest-mock-server
&&npm install
to install the node dependencies - Start the server by executing
npm run watch
- Configure the routes depending on your needs. Therefore open the
config.js
module.exports = {
server: {
port: 3000
},
mocks: [
{
path: "/test",
query: "a=true&b=false&c=1",
responseFile: "./responseFiles/test1.txt",
},
{
path: "/test/2",
responseFile: "./responseFiles/test2.json"
method: "POST",
responseCode: 200
}
];
}
Simplest Mock Server comes bundled with a Postman Collection containing some tests to verify everything is working.
It is run using Newman. These tests are based on the default response files.
Run the tests with:
npm test
Option | Description |
---|---|
server |
Required Server configuration, see Server configuration options .Type: object |
mocks |
Required Array of mocks, see Mock configuration options .Type: array |
Option | Description |
---|---|
port |
Optional Server port to listen. Type: int Default: 3000 |
Option | Description |
---|---|
path |
Required Path to listen for requests. Type: string |
method |
Optional HTTP-Method to listen for. Type: string Default: GET |
query |
Optional Query-String to match, order is not important. Type: string |
responseFile |
Optional Location for the file to return. Type: string |
responseCode |
Optional Response-Code to return. Type: int Default: 200 |
Please feel free to improve or modify the code and send a Pull-Request! Any contribution is very welcome :)
Copyright © 2018 Jan Loebel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.