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 🙏

© 2025 – Pkg Stats / Ryan Hefner

proxy-dynamic-middleware

v0.0.2

Published

Base on http-proxy-middleware, mock config file can take effects dynamically.

Downloads

7

Readme

proxy-dynamic-middleware

It's based on http-proxy-middleware, it help you make you mock config file take effects dynamically.

Usage

const express = require('express');
const mockMiddleWare = require('proxy-dynamic-middleware');
const config = require('../config');

// dynamic require
function requireNoCache(modulePath) {
  delete require.cache[require.resolve(modulePath)];
  return require(modulePath);
}

app.use(mockMiddleWare(() => requireNoCache(config.dev.dynamicConfigPath).mock), {
  // supply an hook to handle response
  onProxyRes: (proxyRes, _req, _res) => {},
  // supply an hook to handle request
  onProxyReq: (proxyReq, _req, _res) => {},
});

If you use webpack-dev-server, you can add after option like this:

  // these devServer options should be customized in /config/index.js
devServer: {
  ...
  after (app) {  // do not use the proxy option
    app.use(mockMiddleWare(() => requireNoCache(config.dev.dynamicConfigPath).mock));
  },
  ...
}

options

MockData options:

{
  open: false, // false not use mock,  true use mock. default false.
  changeOrigin: true, // Proxy rule in rules, set changeOrigin dafault value if not defined or if value is a string. default true
  rules: {
    /**
     * '/API_ROOT' we call outer rule, '*' and '/some/route/to/' we call inner rule
     * If no outer rule match the request.path, then middleware will go next(), nothing happens
     * If outer rule match, but no inner rule match the request.path, proxy to the fallback(default to 'default') url
     * You should know that, the outer root '/API_ROOT' will be ignore if matched when proxys.
     * Example:
     * http://localhost:8080/API_ROOT/some/route/to/here -> http://172.172.2.89:8000/route/to/here
     */
    '/API_ROOT': {
      /**
       * Who match longest, then take effects!
       * Same use like the proxyTable (but changeOrigin be true as default)
       * '*' or '/' or '' match everyone, but match length is considered 1.
       * You can use keywords for mock origins.
       */
      '*': 'mock',
      '/some/route/to/': {
        target: 'dev',
        pathRewrite: {
          '^some': '',
        },
      },
      // Has higher priority than /some/route/to/ as it's longer
      '/some/route/to/there': 'dev'
    },
  },
  /**
   * If you don't set outer rule's fallback, default to 'default'
   * If you set outer rule's fallback to dev
   * when outer rule '/API_ROOT' match, inner rule not match
   * the request will proxy to the 'dev' url
   */
  fallback: {
    '/API_ROOT': 'dev',
  },
  /**
   * 'default' is a special keyword, you should set a value for it
   */
  keywords: {
    'default': 'http://dev.yousite.com/',
    'mock': 'http://yapi.elephtribe.net/mock/1111/',
    'dev': 'http://172.172.2.89:8000',
  },
}