3.0.0 • Published 5 years ago

@gzzhanghao/mocker-utils v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@gzzhanghao/mocker-utils

Utility functions for building mocker's mockup rules.

Usage

npm i -S @gzzhagnaho/mocker-utils

Then import the package in your mocker rules:

//
// Import functions from mocker-utils:
//
// import { file } from '@gzzhangaho/mocker-utils'
//
export default [

  '//www.google.com/', [

    // response `www.google.com` with `/tmp/google.html`
    // request will pass through if the file does not exists
    file('/tmp/google.html'),

    // send request and save the response body into `/tmp/google.html`
    save('/tmp/google.html'),
  ],

  // respond with html content
  '//mocker.io/', [
    req => html(`<h1>It works ${req.query.name}!</h1>`),
  ],

  // respond with json data
  '//mocker.io/awesome-api', [
    req => json({ username: req.query.name }),
  ],

  // add CORS / custom headers to third-party API
  '//awesome.com/api', [
    headers({ 'access-control-expose-headers': 'X-My-Custom-Header' }),
    cors(),
  ],

  // Hijacking WebSocket connection. http://www.websocket.org/echo.html
  'ws://echo.websocket.org', async req => {
    const socket = await ws(req)
    socket.on('message', msg => {
      socket.send(`[MOCKER] ${msg}`)
    })
  },
]
3.0.0

5 years ago

3.0.0-beta.4

5 years ago

3.0.0-beta.3

5 years ago

3.0.0-beta.2

5 years ago

3.0.0-beta.1

5 years ago

3.0.0-beta.0

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.1.3

7 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago