Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-mock-server

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-mock-server

to be the most simple gulp mock tool in the world

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gulp-mock-server


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
 ...
 mockDir: './demo/data'
 ...
generate jsonp interface automatically

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

support https
 ...
 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:

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:

KeyTypeDefaultDescription
paramsObjectNullThe parameters of the meet
delayNumber0Request delay time
codeNumber200Status code (Temporary does not support)
responseObject{}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
$ npm install --save-dev gulp-mock-server
use for commandline
$ npm install -g gulp-mock-server

Usage

first step

make a directory named "data" in the root directory

second step

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

third step

visit url => localhost:8090/test

so easy!

Options

KeyTypeDefaultDescription
hostStringlocalhosthostname of the webserver
portNumber8000port of the webserver
pathString/path to the webserver
mockDirString./datamock directory
livereloadBoolean/Objectfalsewhether 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.
directoryListingBoolean/Objectfalsewhether 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.
fallbackStringundefinedfile to fall back to (relative to webserver root)
openBoolean/Stringfalseopen 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/) .
httpsBoolean/Objectfalsewhether 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'}.
proxiesArray[]a list of proxy objects. Each proxy object can be specified by {source: '/abc', target: 'http://localhost:8080/abc', options: {headers: {'ABC_HEADER': 'abc'}}}.
allowCrossOriginBooleanfalsewhether to allow cross origin calls (CORS)

contributors

sanyueyu,dstj,elwayman02, walkcc

Keywords

FAQs

Package last updated on 12 Jan 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc