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

unmock-server

v0.3.18

Published

[![npm](https://img.shields.io/npm/v/unmock-server.svg)](https://www.npmjs.com/package/unmock-server) [![CircleCI](https://circleci.com/gh/Meeshkan/unmock-js.svg?style=svg)](https://circleci.com/gh/Meeshkan/unmock-js) [![codecov](https://codecov.io/gh/unm

Downloads

4

Readme

unmock-server

npm CircleCI codecov Known Vulnerabilities

Unmock server mocks APIs using unmock-js.

Installation

npm

The npm package ships with unmock-server CLI that you can add either in project or globally.

Install in project

npm install unmock-server
# OR
yarn add unmock-server

Invoke CLI via npx or yarn:

npx unmock-server --help
# OR
yarn unmock-server --help

Install globally

npm install -g unmock-server
# OR
yarn global add unmock-server

In this case, you can invoke unmock-server without npx or yarn:

unmock-server --help

Install from source

  1. Clone unmock-js repository.
  2. Install dependencies: npm i
  3. Build TypeScript: npm run compile
  4. Invoke the CLI: node packages/unmock-server/bin/run

Usage

Start unmock-server with start command:

$ unmock-server start

You may need to add npx or yarn before the command depending on your installation method.

The start command starts

  1. admin server at port 8888 (override with UNMOCK_ADMIN_PORT environment variable) for managing services
  2. proxy server at port 8008 for mocking requests
  3. mock server at port 8000 (HTTP) and 8443 (HTTPS) for internally handling requests made to the proxy.

Stop unmock-server with stop command:

$ unmock-server stop

Using the mock proxy

To use the proxy for mocking requests, you need to:

  1. Define services you want to mock (see below)

  2. Set your HTTP client to use the locally running proxy

    curl: set environment variables

    • http_proxy=http://localhost:8008
    • https_proxy=http://localhost:8008
    • Other clients may expect HTTP_PROXY and HTTPS_PROXY environment variables instead
  3. If mocking a server using HTTPS, you need to fetch the certificate served by the mock proxy:

    Fetch certificate:

    wget https://raw.githubusercontent.com/unmock/unmock-js/dev/packages/unmock-server/certs/ca.pem`

    You then need to add the mock server certificate to the list of trusted certificates. For curl, set environment variable SSL_CERT_FILE=ca.pem

Example calls with cURL

Request to proxy with HTTP:

$ http_proxy=http://localhost:8008 curl -i http://api.github.com/user/repos

Request to proxy with HTTPS:

$ https_proxy=http://localhost:8008 SSL_CERT_FILE=ca.pem curl -i https://api.github.com/user/repos

Request to mock server without using the proxy:

$ curl -i --header "X-Forwarded-Host: api.github.com" http://localhost:8000/user/repos

Managing services

You can manage services either via the admin REST API or through filesystem.

Using the admin server

Get all services:

$ curl http://localhost:8888/services

Post a new service with name my-service:

$ curl -X POST http://localhost:8888/services/my-service -H "Content-Type: application/json" --data "@/path/to/openapi.json"

Get a service description for service with name my-service:

$ curl http://localhost:8888/services/my-service

Using __unmock__ folder

At startup, unmock-server loads all services from __unmock__ folder. For example, to mock api.github.com, you need to

  1. Prepare __unmock__ folder: mkdir -p __unmock__/githubv3
  2. Add the GitHub OpenAPI specification to __unmock__/githubv3:

wget https://raw.githubusercontent.com/unmock/DefinitelyMocked/master/services/githubv3/openapi.yaml -O __unmock__/githubv3/openapi.yaml

When unmock-server is started, it loads the GitHub API with name githubv3. For more detailed instructions, see the Unmock documentation.

Docker

Unmock server can also be used via Docker. See documentation for the unmock/unmock-server Docker image.

Development

Running the CLI

  1. Compile TypeScript by running npm run compile at the root of the monorepo
  2. Invoke ./bin/run or ./bin/run.cmd.

Creating new CA certificate

cd certs/
./openssl-gen.sh