@cc12703m/reed-mock-server
v0.0.21
Published
node.js mock server
Downloads
3
Readme
Reed Mock Server
Full feature mock server.
- Restful API Mock
- Transparent HTTP Proxy
- Websocket Mock
- Static File Serve
How to use
npm i -g reed-mock-server
imock init
# after customized the 'mock-server.json', 'json-api.hbs'
imock start mock-server.json
CLI
imock start -p 3000 -s "/" --static-dir "./dist" --api "/api" --api-data-path "./json-data.hbs" --ws-endpoint "/ws" --ws-data-path "./json-ws.hbs"
imock start -h
# Usage: start [options] [config]
#
# start mock server
#
# Options:
# -p, --port <port> Set port (default: 3000)
# -P, --portal-port <port> Set portal port (default: 3001)
# -s, --static-endpoint <path> Set static server endpoint
# --static-dir <dir> Set static files directory (default: "./dist")
# --api, --api-endpoint <path> Set api endpoint
# --api-data-path <dir> Set api data config's path (default: "./json-api.hbs")
# --ws, --ws-endpoint <path> Set Websocket webpoint
# --ws-data-path <dir> Set Websocket data config's path (default: "./json-ws.hbs")
# --nc, --no-cors Disable Cross-Origin Resource Sharing
# -h, --help output usage information
Sample mock server config json
{
"port": "3000",
"timeout": 300,
"serveStatic": {
"enabled": true,
"endpoints": [
{
"endpoint": "",
"indexPages": [
"index.html",
"index.htm"
],
"dirPath": "./dist"
}
]
},
"serveApi": {
"enabled": true,
"endpoints": [
{
"name": "api1",
"endpoint": "/api",
"filePath": "./json-api.hbs",
"options": {}
}
]
},
"servePath": {
"enabled": true,
"endpoints": [
{
"endpoint": "/apipath/:name/:repo",
"type": "get",
"filePath": "./sample/templates/json-path.hbs",
"partial": {
"owner": "./sample/templates/json-path-owner.hbs",
"author": "./sample/templates/json-path-author.hbs"
},
"options": {}
},
{
"endpoint": "/apipath-js/:name",
"type": "get",
"filePath": "./sample/templates/code-path.js",
"options": {}
}
]
},
"serveWebsocket": {
"enabled": true,
"endpoints": [
{
"endpoint": "/ws",
"filePath": "./json-ws.hbs",
"type": "timer",
"interval": "500"
}
],
"options": {}
},
"serveSocketIO": {
"enabled": true,
"endpoint": "/sio",
"namespaces": [
{
"namespace": "/nsp",
"event": "notify",
"filePath": "./sample/templates/json-ws.hbs",
"type": "fileWatcher"
}
],
"options": {}
},
"serveProxy": {
"enabled": true,
"endpoints": [
{
"endpoint": "/proxy-foo",
"target": "http://some-service/api/"
}
],
"options": {}
},
"customMiddleware": {
"front": [],
"last": []
},
"portal": {
"port": 3001
}
}
More custom options
API proxy is powered by http-proxy, more options could be found here.
Json data generation is powered by dummy-json, available helpers could be found here
How to Debug
serveStatic
,serveApi
,servePath
can use curlserveWebsocket
can use wscatserveSocketIO
can use debugSIO.html
Publish
- run
npm pack && npm publish --access public
TODO
- Add Cache control for static file serve