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

parrot-mocker

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parrot-mocker

Intercept requests to the mock server

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

parrot-mocker npm version Build Status Coverage Status License

This package supports to intercept XHR/JSONP/Fetch requests and forward to the specified mock server.

How to use

Chrome plugin

Install from Chrome web store.

Or load the plugin by following Google's development guide. The plugin folder is crx.

If the development mode plugin is disabled by Chrome, you can uninstall and install it again.

Standalone

<head>
    <!-- Make sure to be loaded first -->
    <script type="text/javascript" src="dist/parrot.js"></script>
</head>

Webpack

// Modifiy webpack.config.js to prepend this package to dependencies of each entry
module.exports = {
    entry: ['parrot-mocker', './yours/src/entry.js']  
};

Node.js

We export a function to rewrite the request url.

wrapUrl(urlStr, options)
  • urlStr string the url of the API request
  • options
    • reqType string the type of request, like jsonp
    • pageUrl string the url of the page
    • cookie string the cookie of the page request
    • shouldSkip function skip rewritting if returns true. By default, no host or including local will be filtered. Its arguments are:
      • host string the API host

For example, let's make a simple middleware for Koa,

var fetch = require('node-fetch');
var wrapUrl = require('parrot-mocker').wrapUrl;

module.exports = function*(next) {
    this.fetch = (url, options) => {
        return fetch(wrapUrl(url, {
            pageUrl: this.url,
            cookie: this.header.cookie
        }));
    };

    yield* next;
};

License

MIT

Acknowledgement

Keywords

FAQs

Package last updated on 07 Jul 2018

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