Socket
Socket
Sign inDemoInstall

parrot-mocker-web

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parrot-mocker-web

Retransmit requests to real servers or just mock


Version published
Maintainers
1
Created
Source

parrot-mocker-web npm version Build Status Coverage Status License

中文文档

This project provides a simple mock server, which works with the Chrome plugin parrot-mocker.

Support:

  • foward requests of pages(xhr/jsonp/fetch) to the real web server, or just mock
  • list all forwarded requests
  • config mock rules for different requests

Not support:

  • cookie sensitive requests, because the plugin forwards requests with cookies of the page, instead of cookies of the request domain
  • relative or local DNS parsed requests, because the mock server can not resolve them
  • HTTPS pages, unless the mock server is deployed with HTTPS (Solved by leancloud and now.sh)

How to use

1.Prepare

Install Chrome plugin, parrot-mocker, so that your pages have the ablity to intercept requests and forward to this mock server. Other usages without the plugin can refer to parrot-mocker project.

2.Visit

For example, if deployed in leancloud, please open your Chrome browser and visit index page first. Other instances like now.sh are similar.

Then visit your test page, i.e. my demo, which will send 3 different requests(xhr/jsonp/fetch) after loaded.

In the plugin, input the mock server address and click the green button. The test page will reload automatically.

Now you will find that requests are forwarded to the mock server, which are also visiable at index page. If visiting other pages in the same domain, their requests will also be forwarded to this mock server.

3.Mock

Click any request in the list, and click 'Add'. Then this request is added to mock.

Open config page, now you can edit the mock data. Remember to click 'Apply' to really use the mock data.

Refresh your test page to check whether the mock is working correctly.

Launch locally

By default, the server is launched on main port 8080, and sub-ports 8442/8443. Sub-ports can be visited by http/https correspondingly. Because my https is self-certified, if your browser gives a warning, please continue to visit.

node ./server/index.js

Or you can specify the port by an environment variable.

PORT=8888 HTTP_PORT=9442 HTTPS_PORT=9443 node ./server/index.js

Local index page is http://127.0.0.1:8080. You should use this address as mock server in step 2, and other steps are similar with above.

License

MIT

Acknowledgement

Keywords

FAQs

Package last updated on 27 Sep 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