
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
proxy-dynamic-middleware
Advanced tools
Base on http-proxy-middleware, mock config file can take effects dynamically.
It's based on http-proxy-middleware, it help you make you mock config file take effects dynamically.
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));
},
...
}
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',
},
}
FAQs
Base on http-proxy-middleware, mock config file can take effects dynamically.
We found that proxy-dynamic-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.