# gulp-mock-server

> to be the most simple gulp mock tool in the world

Latest version **1.1.4** (published 2017-03-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-mock-server
pnpm add gulp-mock-server
yarn add gulp-mock-server
bun add gulp-mock-server
```

Provides the command `mock`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2017-03-07 |
| First published | 2015-09-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 23 |
| Known vulnerabilities | 0 (+6 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 32 |
| Author | 普修 |
| Maintainers | sanyueyu |
| Keywords | gulp, mock, webserver |

## Links

- npm: https://www.npmjs.com/package/gulp-mock-server
- Repository: https://github.com/sanyueyu/gulp-mock-server
- Homepage: https://github.com/sanyueyu/gulp-mock-server#readme
- Issues: https://github.com/sanyueyu/gulp-mock-server/issues
- npm.io page: https://npm.io/package/gulp-mock-server

## Dependencies (23)

- [rd](https://npm.io/package/rd.md) 0.0.2
- [gulp](https://npm.io/package/gulp.md) ^3.9.0
- [open](https://npm.io/package/open.md) ^0.0.5
- [watch](https://npm.io/package/watch.md) ^0.11.0
- [colors](https://npm.io/package/colors.md) ~1.1.2
- [connect](https://npm.io/package/connect.md) ^3.0.1
- [isarray](https://npm.io/package/isarray.md) 0.0.1
- [mini-lr](https://npm.io/package/mini-lr.md) ^0.1.8
- [request](https://npm.io/package/request.md) ^2.72.0
- [tiny-lr](https://npm.io/package/tiny-lr.md) 0.1.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.30.0
- [optimist](https://npm.io/package/optimist.md) ~0.6.1
- [through2](https://npm.io/package/through2.md) ^0.5.1
- [commander](https://npm.io/package/commander.md) ~2.9.0
- [gulp-util](https://npm.io/package/gulp-util.md) ^2.2.19
- [body-parser](https://npm.io/package/body-parser.md) ~1.14.1
- [node.extend](https://npm.io/package/node.extend.md) ^1.0.10
- [serve-index](https://npm.io/package/serve-index.md) ^1.1.4
- [serve-static](https://npm.io/package/serve-static.md) ^1.3.0
- [connect-query](https://npm.io/package/connect-query.md) ^0.2.0
- [proxy-middleware](https://npm.io/package/proxy-middleware.md) ^0.5.0
- [connect-livereload](https://npm.io/package/connect-livereload.md) ^0.4.0
- [connect-multiparty](https://npm.io/package/connect-multiparty.md) ^2.0.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [facebook-ads-library-api](https://npm.io/package/facebook-ads-library-api.md) — 0 weekly downloads
- [@comp-markdown/wireframe](https://npm.io/package/@comp-markdown/wireframe.md) — 0 weekly downloads
- [generador-datos-mx](https://npm.io/package/generador-datos-mx.md) — 0 weekly downloads

## Recent versions

- 1.1.4 (latest) — 2017-03-07
- 1.1.3 — 2017-01-12
- 1.1.2 — 2016-07-31
- 1.1.1 — 2016-06-07
- 1.1.0 — 2016-06-07
- 1.0.22 — 2016-05-07
- 1.0.21 — 2016-05-06
- 1.0.20 — 2016-04-27
- 1.0.19 — 2016-04-18
- 1.0.18 — 2016-04-12
- 1.0.17 — 2016-03-26
- 1.0.16 — 2016-03-24
- 1.0.15 — 2016-02-25
- 1.0.14 — 2016-02-22
- 1.0.13 — 2016-02-21
- … 13 more at https://npm.io/package/gulp-mock-server/versions

## README

# gulp-mock-server
<img src="http://gtms04.alicdn.com/tps/i4/TB1cqoFLpXXXXXbXFXXF3Q4QpXX-300-320.png" /><br />
### A gulp tool also a commandline tool for local mock data,everything for simple!


## feature
#### json files in data directory(default named data) generate interface automatically
_ => means  real request _
 >'host + /test'  => response file 'data/test.json'

 >'host + /test.do'  => response file 'data/test.do.json'

#### change mock directory, default named 'data' directory in your project
```javascript
 ...
 mockDir: './demo/data'
 ...
```
#### generate jsonp interface automatically

 >'host + /test.jsonp?callback=cb'  => response file 'data/test.jsonp.json'

#### support https
```javascript
 ...
 https: true
 ...
```
#### multi-level directory such as:

 >'host + /class/xiaoming'  => response file 'data/class/xiaoming.json'

#### different params different response by get or post request

/data/check.do.js content:

```javascript
module.exports = {
  params: {id: 123},
  response: './check_one.json'
}
```
or

```javascript
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
`route` | String | Null | Request url
`code` | Number  | 200 | Status code (Temporary does not support)
`response` | Object | {} | The data returned

#### support powerful command line
Options:
- -h, --help               output usage information
- -v, --version            output the version number
- -e, --server [mockRoot]  start mock server, such as: mock -e
- -p, --port [port]        server port config, such as: mock -e -p 8000
- -f, --fetch [url]        download remote url to local json file, such as: mock -f http://hostname/api/test.do

#### may be others...

## Install

#### use for gulp
```sh
$ npm install --save-dev gulp-mock-server
```
#### use for commandline
```sh
$ npm install -g gulp-mock-server
```

## Usage

### first step
make a directory named "data" in the root directory

### second step
webserver config:

```js
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

### third step
visit url => localhost:8090/test

 so easy!

## Options

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](https://github.com/expressjs/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)

## contributors

[sanyueyu](https://github.com/sanyueyu),[dstj](https://github.com/dstj),[elwayman02](https://github.com/elwayman02),
[walkcc](https://github.com/walkcc)

---
_Source: https://npm.io/package/gulp-mock-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
