Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
gulp-mock-server
Advanced tools
_ => means real request _
'host + /test' => response file 'data/test.json'
'host + /test.do' => response file 'data/test.do.json'
...
mockDir: './demo/data'
...
'host + /test.jsonp?callback=cb' => response file 'data/test.jsonp.json'
...
https: true
...
'host + /class/xiaoming' => response file 'data/class/xiaoming.json'
/data/check.do.js content:
module.exports = {
params: {id: 123},
response: './check_one.json'
}
or
module.exports = [{
params: {id: 123},
response: './check_one.json'
}, {
params: {id: 456},
response: './check_two.json'
}, {
params: {id: 789},
response: {
name: "three"
}
}]
'host + /check.do' => response file 'data/check.do.js'
'host + /check.do?id=123' => response file 'data/check_one.json'
'host + /check.do?id=789' => response content '{"name":"three"}'
configs:
Key | Type | Default | Description |
---|---|---|---|
params | Object | Null | The parameters of the meet |
delay | Number | 0 | Request delay time |
code | Number | 200 | Status code (Temporary does not support) |
response | Object | {} | The data returned |
Options:
$ npm install --save-dev gulp-mock-server
$ npm install -g gulp-mock-server
make a directory named "data" in the root directory
webserver config:
var gulp = require('gulp');
var mockServer = require('gulp-mock-server');
gulp.task('mock', function() {
gulp.src('.')
.pipe(mockServer({
port: 8090
}));
});
put a json file such as "test.json" in the "/data" directory
visit url => localhost:8090/test
so easy!
Key | Type | Default | Description |
---|---|---|---|
host | String | localhost | hostname of the webserver |
port | Number | 8000 | port of the webserver |
path | String | / | path to the webserver |
mockDir | String | ./data | mock directory |
livereload | Boolean/Object | false | whether to use livereload. For advanced options, provide an object. You can use the 'port' property to set a custom live reload port and the filter function to filter out files to watch. The object also needs to set enable property to true (e.g. enable: true ) in order to activate the livereload mode. It is off by default. |
directoryListing | Boolean/Object | false | whether to display a directory listing. For advanced options, provide an object with the 'enable' property set to true. You can use the 'path' property to set a custom path or the 'options' property to set custom serve-index options. |
fallback | String | undefined | file to fall back to (relative to webserver root) |
open | Boolean/String | false | open the localhost server in the browser. By providing a String you can specify the path to open (for complete path, use the complete url http://my-server:8080/public/ ) . |
https | Boolean/Object | false | whether to use https or not. By default, gulp-webserver provides you with a development certificate but you remain free to specify a path for your key and certificate by providing an object like this one: {key: 'path/to/key.pem', cert: 'path/to/cert.pem'} . |
proxies | Array | [] | a list of proxy objects. Each proxy object can be specified by {source: '/abc', target: 'http://localhost:8080/abc', options: {headers: {'ABC_HEADER': 'abc'}}} . |
allowCrossOrigin | Boolean | false | whether to allow cross origin calls (CORS) |
FAQs
to be the most simple gulp mock tool in the world
We found that gulp-mock-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.