
Security News
GPT-6 Astra Attempts Supply Chain Attacks Against Open Source Maintainers in Testing
GPT-6 Astra hits 100% on ExploitBench and finds zero-days autonomously, while independent tests reveal scope violations and monitoring gaps.
mock-proxy-server
Advanced tools
一个HTTP代理服务器,能够根据配置修改通过此代理服务器的请求,为指定请求返回mock数据,修改请求头、响应头,也可实现请求转发、延迟响应的功能。
npm install -g mock-proxy-server
mock-proxy-server - c <配置文件路径>
如果未指定配置文件,程序会在当前目录中自动生成,路径为/mock_server/rule.js
本程序基于anyproxy实现,更加详细的使用手册可以参考anyproxy
module.exports = {
plugins: [
{
name: 'mock',
mock: {
'/test': {
code: 200,
message: '1234'
}
}
}
],
"anyproxy": {
"port": 8001,
"webInterface": {
"webPort": 8002,
"wsPort": 8003
},
"forceProxyHttps": true,
"silent": true
}
}
plugins声明代理服务器中使用的插件及其配置
anyproxy声明代理服务器配置,参加anyproxy
拦截指定请求,返回mock数据,如下面配置,为所有包含localhost, /test的请求,延迟1000ms后,返回json数据。
{
name: 'mock',
include: ['localhost'],
exclude: [],
delay: 1000,
mock: {
'/test': {
code: 200,
message: '1234'
}
}
}
将指定请求代理到特定的服务器,如下面的配置,当请求https://a.com/a.js时,会返回http://localhost/b.js的数据;当请求https://b.com/a.js时,会返回http://localhost/a.js的数据。
{
name: 'proxy',
proxy: {
'https://a.com/a.js': 'http://localhost/b.js',
'https://b.com/(.*)': 'http://localhost/[$1]'
}
}
对响应报头进行修改,如下面配置,为所有包含localhost的请求添加控制缓存的响应报头
{
name: 'resHeader',
include: ['localhost'],
exclude: [],
header: {
'Cache-Control': 'max-age=2592000',
'Expires': 'Thu, 26 Oct 2017 03:20:53 GMT',
'Pragma': '',
'Last-Modified': ''
}
}
include, exclude : 对经过代理服务器的请求进行筛选。
delay: 延迟一段时间后再返回数据
一个decorator的形式类似于:
/**
* @param {Object} opts 传递给plugin的参数
* @param {Object} last 上一个plugin返回的数据
* @return {Promise} resolve后,后续的decorator或plugin才会开始执行,如果reject, 后续的decorator和plugin都不会执行
*/
function (opts, last) {
}
一个plugin的格式类似于:
/**
* @param {Object} opts 传递给plugin的参数
* @param {Object} last 上一个plugin返回的数据
* @param {Any} 可以返回任何类型,可以为Promise
*/
function (opts, last) {
}
FAQs
一个HTTP代理服务器,能够根据配置修改通过此代理服务器的请求,为指定请求返回mock数据,修改请求头、响应头,也可实现请求转发、延迟响应的功能。
The npm package mock-proxy-server receives a total of 7 weekly downloads. As such, mock-proxy-server popularity was classified as not popular.
We found that mock-proxy-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
GPT-6 Astra hits 100% on ExploitBench and finds zero-days autonomously, while independent tests reveal scope violations and monitoring gaps.

Product
Socket can now send alerts and supply chain attack notifications to Microsoft Teams, with filters that route the right updates to each channel.

Security News
pnpm 12 rewrites the package manager in Rust, cutting install times by up to 90% while preserving pnpm 11 workflows and lockfiles.