
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.
express-mock-api
Advanced tools
简单、强大的mock请求的express插件
本插件中有几个关键词需要注意,同时也为了避免混淆
初始化时需要传入两个信息:
const path = require('path')
const mock = require('express-mock-api');
app.use(mock({
root: path.resolve('./mock'), // 这里指定mock文件夹
ignore: '/public/' // 这里设置忽略的请求路径
}));
注意:
module.exports = {
hot: true, // 是否进行热替换。如果为true表示,修改这个文件会即时生效
paths: {
"/don't/mock/this/path/": false,
"/mock/by/function/": function() {...}, // 这是一个方法
"/user/:id": require('./user/id') // 加载处理文件,其实同上,也是一个方法
}
}
paths是一个map对象,键名为匹配Url的规则,键值为匹配成功后要进行的处理。
键名
键值
键值不同的值代表要进行不同的处理,有如下几种情况:
function(req, res) { res.json({ "result": "ok" }) }
如果是需要一个运行在本机的Server,建议使用 generator-devserver 而非直接使用本包
FAQs
简单、强大的mock请求的express插件
We found that express-mock-api 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
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.