This application creates a mock http server that supports static files and webservices implementation providing a simple configuration file to the application.
It also acts as a module that can run inside other applications.
httpd-mock [-c, --config <path>] [-O, --output] [-p <port>] [-r <rootpath>]
If you provide a configuration file and command line arguments that conflicts,
those arguments will override.
A JSON file containing the following structure:
{
"serverRootPath": "./public", // default value
"servicesPrefix": '/api/', // default value
"jsonMocksPath": "./mocks/", // default value
"output": "false", // default value
"webServices": {
"get": {
"YOUR_WEBSERVICE_URI": "WEBSERVICE_JSON_RESULT_FILE.json",
"YOUR_WEBSERVICE_URI": "WEBSERVICE_JSON_RESULT_FILE.json"
},
"post": {
"YOUR_WEBSERVICE_URI": "WEBSERVICE_JSON_RESULT_FILE.json",
"YOUR_WEBSERVICE_URI": "WEBSERVICE_JSON_RESULT_FILE.json"
}
}
}
The web service URI can contain variables, for instance, "client/:id" would be caught in a request to "client/123".
Only get and post methods are supported for the time being.
var HttpdMock = require('httpd-mock'),
httpdMock = new HttpdMock();
httpdMock
.setConfigFile('pathtofile.json');
.start();
When used as a module an instance of the module will create a object with the interface documented below.
Creates the object. Set options. Object structure is the same as the config.
Registers the web services received as argument, fallbacks to config.
Returns the express instance of the mock server.
Returns the listener instance of the web server.
Returns the port that the server is listening to.
Path to the config file.
Set options. Object structure is the same as the config.
Sets the root path of the server. Remember the server is static. Any server side language won't be supported.
Start the http server on the port received as argument, fallbacks to config, if null fallbacks to random.
- Support different mock JSON files being returned when web service contains
variables in the path for bigger testing scope
- Implement other HTTP methods
- Shell command line to edit web services on the fly