
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
socket-mock
Advanced tools
npm install socket-mock -g
具体用法可参考 test目录
// 举例:项目根目录/mock/ 存放假数据相关文件
// 配置文件 mock/conf.js
module.exports = {
// 默认推送的时间间隔
interval: 1000,
// 服务端口
port: 9096,
// 【必须】假数据文件目录相对路径(相对于node命令的执行路径)
pushDir: 'mock/socket'
//广播假数据路径为$pushDir/broadcast
}
// 全局安装,命令行使用
$ socket-mock -c mock/conf.js
// npm项目中使用
$ npm install socket-mock
// npm scripts
$ npm run mock
// package.json
{
"scripts": {
"mock": "socket-mock -c mock/conf.js",
}
}
mock规则文档:http://mockjs.com/
简单示例:
// 响应数据
{
//'connection'代表服务器接收到的事件
'connection': {
//responseName为服务器返回给客户端的事件名称
responseName: 'serverConnectSuccess',
//response为服务器返回给客户端的数据
response: {
'timestamp':Date.now();
}
}
}
// 广播数据
{
//推送事件
serverSyncEvent: {
//推送事件间隔
interval: 2000,
//推送开始时间
startHour: 9,
//推送结束时间
endHour: 22,
//推送数据
response: function(client) {
return {
"result":
{
"buyPrice": "197.27",
"commodityId": "LSPD1g",
"highPrice": "197.37",
"lowPrice": "195.96",
"openMarketPrice": "196.06",
"preCloseMarketPrice": "195.16",
"preSettlePrice": "195.19",
"sellPrice": "197.27",
"timestamp": Date.now()
}
}
}
}
}
//监听系统开始与退出
//监听规则写在$pushDir/system目录下,目前支持监听system_start,system_exit
'use strict'
module.exports = {
system_start: function () {
console.log('system start');
},
system_exit: function () {
console.log('system exit');
}
};
高级示例:
// response若为函数,则每次请求均会执行。
// 需要对请求编程时可使用,可以自己处理响应
{
//对于相应数据来说,client为socket对象,data为客户端传过来的数据
response: function(client, data){
}
//对于广播数据来说,client为socket对象
response: function(client){
// 私有代码
}
}
FAQs
We found that socket-mock 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.
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
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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.