npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mockingjays

v2.2.1

Published

Mockingjays is a proxying library that responds with previously observed responses.

Downloads

41

Readme

Mockingjays

Circle CI Build Status npm version Gitter

Mockingjays is a proxying tool that responds to requests with responses that have been previously observed.

Mockingjays acts as a mock server for previously seen requests and captures new request for future use.

Install Mockingjays

npm install -g mockingjays

CLI Use

mockingjays serve\
  --cacheDir=/var/app/fixtures \ # Required
  --serverBaseUrl='http://swapi.co' \ # Required
  --cacheHeader='authorization,content-length'
  --ignoreContentType='image/*,text/html' \
  --port=9000 \
  --refresh=true \

Subcommands

There are two subcommands that will indicate to Mockingjays what should be done. These modes are serve and rehash.

serve starts up the proxy server that observes and responds to requests.

rehash is a process in which the provided options will be parsed, and then applied to the existing cache. The rehash command is useful for updating the url of the source server, removing headers from the response and request data.

Javascript API

var Mockingjays = require('mockingjays');

new Mockingjays().start({
  cacheDir: '/var/app/fixtures', // Required
  serverBaseUrl: 'http://swapi.co', // Required
  cacheHeader: 'authorization,content-length',
  ignoreContentType: 'image/*,text/html',
  port: 9000,
  refresh: true
});

Methods

start - Start creates a Mockingjays server and starts proxying or mocking responses based on previous training. stop - Stops an existing Mockingjays server. rehash - Processes the existing cache with a new set of options.

Options

  • serverBaseUrl -Place where an unseen request can be learned.
    • Required
  • cacheDir - Directory where request/response data should be stored.
    • Required
  • cacheHeader - Headers that should be considered as part of the cache signature. By default all headers are ignored in the cache signature.
    • Default: ''
  • logLevel - The Level of Logging information that should be displayed to the console.
    • The available options are ranked from least info to most info:
      • none - Nothing is logged.
      • error - Only errors are logged.
      • warn - Errors and warnings are logged.
      • info - Errors, warnings, and info are logged.
      • debug - Everything is logged.
    • Default: info
  • port - Port that the proxy server should bind to.
    • Default: 9000
  • ignoreContentType - Comma separated list of content-types that should be skipped. This can include a * which will be a wildcard match equivalent to the .* RegEx. No File Types Ignored by default.
    • Default: []
  • refresh - Indicates if the request/response cache should be updated unconditionally.
    • Default: false
  • passthrough - Indicates if the request/response cache should be ignored. Each request will passthrough the proxy, but not read/write to any cache files.
    • Default: false
  • queryParameterBlacklist - Comma separated list of query parameters that should not be cached.
  • Default: ''
  • responseHeaderBlacklist - Indicates headers that should not be recorded to the cache file. Things like date or fields that may change the file during refreshes are ideal candidates.
    • Default: [] (Record all headers)
  • transitionConfig - Path or Object to the transition config Object. The transition config defined a mapping between requests that cause state changes, and the requests that are affected. See Feature File for Example
    • Default: {} (Consider All Operations Non-Stateful)
  • whiteLabel - When set to true, the hostname and port number are not included as part of the request hash.
    • Default: false (Consider hostname and port for cache)
  • ignoreJsonBodyPath - The path of a JSON request body to ignore in uniqueness signature. By default no paths will be ignored. eg: a.b.c to ignore property c inside nested objects a and b.
    • CLI: Comma separated list of paths to ignore.
    • JS: Use Array of paths to ignore.

Cached Responses

The root of cached responses specified by the cacheDir option. Each response is then stored in a subdirectory that matches the path for the request.

For example, a request to the path: /api/ when the cacheDir option has the value of /var/app/fixtures will be stored in /var/app/fixtures/api/{sha1_request_hash} where sha1_request_hash is a hash value of the http request.

Request with deeper paths such as /api/people/1/ will create a deep directory structure inside the root of the cacheDir.

Cached Responses

Each cached response has the following format:

{
  "request": { /* Request Being Proxied */ }
  "status": 200, /* Response Status Code */
  "type": "application/json", /* Response Content Type */
  "headers": { /* Response Headers */ }
  "data": { /* Response Payload */ }  // Can be object or string base on content type
}

Example Response:

{
  "request": {
    "hostname": "swapi.co",
    "port": 80,
    "path": "/api/",
    "method": "GET",
    "headers": {},
    "body": "",
    "transaction": ""
  },
  "status": 200,
  "type": "application/json",
  "headers": {
    "content-type": "application/json",
    "allow": "GET, HEAD, OPTIONS",
    "x-frame-options": "SAMEORIGIN"
  },
  "data": {
    "people": "http://swapi.co/api/people/",
    "planets": "http://swapi.co/api/planets/",
    "films": "http://swapi.co/api/films/",
    "species": "http://swapi.co/api/species/",
    "vehicles": "http://swapi.co/api/vehicles/",
    "starships": "http://swapi.co/api/starships/"
  }
}

Contribute

Contributions are welcome to the repository. There are a number of outstanding issues, which we hope will enhance existing functionality, fix bugs, or add new functionality.

Please add an issue to propose new features, report bugs, and propose improvements.

Git Hub Issues for Mockingjays

Questions

If you have questions about the use of Mockingjays please leave a message in the project's Gitter Chat Room.

Gitter

ChangeLog

For a list of changes between versions please see the CHANGELOG file.

License: Apache 2.0

Copyright 2018 Bladymir Tellez<[email protected]>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.