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

@stuntman/server

v0.3.6

Published

Stuntman - HTTP proxy / mock server with API

Downloads

9,339

Readme

Stuntman server

npm Build Status Coverage Status License

Stuntman is a proxy/mock server that can be deployed remotely together with your application under test, working as either pass-through proxy allowing you to inspect traffic or proxy/mock which can intercept requests/responses and modify them or stub with predefined ones.

It offers API and client library that can be used for example within E2E functional test scripts to dynamically alter it's behaviour for specific traffic matching set of rules of your definition.

In order to get more familiar with the concept and how to use it please refer to example app

NOTE: This project is at a very early stage of developement and as such may often contain breaking changes in upcoming releases before reaching stable version 1.0.0

Building from source

Prerequisites

  • pnpm package manager
  • nvm node version manager (optional)
nvm use
pnpm install
pnpm build

Start server

pnpm stuntman

Configuration

Stuntman uses config

You can create config/default.json with settings of your liking matching Stuntman.Config type

Running as a package

Install with package manager of your choice

npm install @stuntman/server
yarn add @stuntman/server
pnpm add @stuntman/server

Run from bin

stuntman
yarn stuntman
node ./node_modules/.bin/stuntman

Run programatically

import { Mock } from '../mock';
import { stuntmanConfig } from '@stuntman/shared';

const mock = new Mock(stuntmanConfig);

mock.start();

Point domain to localhost

Add some domains with .stuntman suffix (or .stuntmanhttp / .stuntmanhttps depending where you want to direct the traffic in proxy mode) to your /etc/hosts for example

127.0.0.1 www.example.com.stuntman

Try in browser

go to your browser and visit http://www.example.com.stuntman:2015/ to see the proxied page for local playground you can also use http://www.example.com.localhost:2015

Take a look at client

Mind the scope of Stuntman.RemotableFunction like matches, modifyRequest, modifyResponse. Stuntman.RemotableFunction.localFn contains the function, but since it'll be executed on a remote mock server it cannot access any variables outside it's body. In order to pass variable values into the function use Stuntman.RemotableFunction.variables for example:

    matches: {
        localFn: (req) => {
            // you might need to ignore typescript errors about undefined variables in this scope
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            return /http:\/\/[^/]+\/somepath$/.test(req.url) && req.url.includes(`?someparam=${myVar}`);
        },
        localVariables: { myVar: 'myValue' },
    }

You can build the rules using fluentish ruleBuilder

import { Client } from './apiClient';
import { ruleBuilder } from './ruleBuilder';

const client = new Client();

const uniqueQaUserEmail = '[email protected]';
const rule = ruleBuilder()
    .limitedUse(2)
    .onRequestToHostname('example.com')
    .withSearchParam('user', uniqueQaUserEmail)
    .mockResponse({
        localFn: (req) => {
            if (JSON.parse(req.body).email !== uniqueQaUserEmail) {
                return {
                    status: 500,
                };
            }
            return { status: 201 };
        },
        localVariables: { uniqueQaUserEmail },
    });

client.addRule(rule).then((x) => console.log(x));

Take a look at PoC of WebGUI

....just don't look to closely, it's very much incomplete and hacky

  • http://stuntman:1985/webgui/rules - rule viewer/editor
  • http://stuntman:1985/webgui/traffic - traffic viewer for the rules that store traffic